Easy way to work with Time Zones

Hello,

I have a problem. How can I easily work with different time zone client of my asp.net 2.0 application live at different part of the states, and I like to write a vb class to handle there time. Help

Alan,



Answer this question

Easy way to work with Time Zones

  • Nauman Raza

    But let say if i store all my data with UTC, i am in PST, how can I get the time Mountain Standard Time I can't just UTCNow.AddHour(2) because users don't just use my application from Mountain Standard Time. LocalTime may work, but another area may need to access another time zone info. Anyway the main point is I wish I can convert UTC to specific Time Zone, without hand coding all the offsets nad take Daylight saving in to account.

    Thanks....


  • ColleenR

    thanks for the reply.

    how about this.. let say i store all my time in UTC format, how can i convert back to Pacific Standand Time (PST) Central Time How does DST will be resolved

    Thank you very very much...

    Alan,


  • skyshock21

    If your asking is there a simple

    There's no ConvertTimezone(sourceTimezone, destinationTimeZone, datetime ) call in the language or the framework out of the box. The answer is no.

    The functions I detailed will convert from local time on the machine to/from UTC Time but if you want to convert from say mountain to eastern then you'll have to either code something or get a 3rd party component.

    http://www.dotnet247.com/247reference/msgs/46/230600.aspx

    details what I think your looking to do and provides a possible (unverified way) of getting the timezone information which may if modified provide you with a way to do this.


  • Rafal Struzyk

    I'm not sure what your exactly asking for here.

    If you want to store the date/time in a value which can be used to ensure that you can determine the actual time of say a transaction on a coordinated basis then Universal time is what you would be looking at. Then you can convert between local and universal time with ease. So they see local time on there applications but you are actually storing Universal Time behind the scenes.

    Label1.Text = Now.ToUniversalTime
    Label2.Text = Now.ToLocalTime

    Label3.Text = UTCNow

    http://msdn2.microsoft.com/en-us/library/497a406b(vs.80).aspx


  • apclogan

    If you store everything in Universal Time, then use the ToLocalTime which will display the local time on that machine.

    The specific time zone for that machine is set in control panel.

    ToLocalTime
    http://msdn2.microsoft.com/en-us/library/system.datetime.tolocaltime.aspx

    Converts the value of the current DateTime object to local time.
    In the documentation for the function it states "The conversion also takes into account the daylight saving time rule that applies to the time represented by the current DateTime object. "

    So it sounds like Daylight savings is resolved automatically by this function.


  • Easy way to work with Time Zones