Re: Timezone conversion

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



I've been using the ToUniversalTime object with great success until we moved
the clocks forward for daylight savins time. Now, ToUniversalTime shows UTC
+ 1 hour. How can I compensate for this automatically?

Brett

"Jason Penniman" wrote:

> Sorry... in Java mode these days... The Calendar class in .Net doesn't allow
> you to set the timezone. There is a TimeZone class, but it also uses the
> timezone of the current computer.
>
> Looks like, if you want that flexability, you're going to have to write you
> own. You could Inherit the TimeZone class (DateTime is a structure and not
> inheritable) and overload the ToLocalTime() method. That way, your new
> class has all the other functionality you need to work with TimeZones and
> UTC time.
>
> Something like....
>
> public DateTime ToLocalTime(DateTime dt, string tz) {
> if (tz.ToLower().Equals("pst")) {
> return dt.AddHours(-8);
> }
> }
>
> Obviously, you'll have to get a litte more fancy to get around the daylight
> savings time problem. You'll have to test it to get the math right, but you
> can use the TimeZone.IsDaylightSavingTime method coupled with the
> DaylightTime class to check if the date is within daylight savings time.
>
>
>
>
>
> "Bijoy Naick" <b_naick@xxxxxxxx> wrote in message
> news:eBu29dG5EHA.1596@xxxxxxxxxxxxxxxxxxxxxxx
> > do u have any examples of the calendar object?
> >
> > "Jason Penniman" <jpenniman@xxxxxxxxxx> wrote in message
> > news:OvaWnbG5EHA.3648@xxxxxxxxxxxxxxxxxxxxxxx
> >> Yes they will. Let's say you need to convert the current time.
> >>
> >> DateTime currentTime = DateTime.Now;
> >> DateTime utcTime = currentTime.ToUniveralTime();
> >>
> >> or the short version: DateTime utcTime = DateTime.Now.ToUniversalTime();
> >>
> >> If you need to use a date other than "now":
> >>
> >> DateTime myDate = DateTime.Parse("7/4/2004 13:00:00");
> >> DateTime utcTime = myDate.ToUniversalTime();
> >>
> >> the short version: DateTime utcTime = DateTime.Parse("7/4/2004
> >> 13:00:00").ToUniversalTime();
> >>
> >> To convert back:
> >>
> >> DateTime myDate = utcTime.ToLocalTime();
> >>
> >> Of course, this example assumes you are using the timezone of the machine
> >> the application lives on. If you're on the east cost and need to convert
> > to
> >> pacific, you can use the Calendar Object to set the locale and pull your
> >> dates/times from that. Though, if you need that flexability, and are
> > going
> >> to bu reusing that code, I would take the custom utility class approach.
> >>
> >>
> >> "Bijoy Naick" <b_naick@xxxxxxxx> wrote in message
> >> news:uVKXcCG5EHA.1120@xxxxxxxxxxxxxxxxxxxxxxx
> >> > these functions wont allow me to convert a time in Pacific time to
> >> > UTC..
> >> > will they?
> >> >
> >> > "Jason Penniman" <jpenniman@xxxxxxxxxx> wrote in message
> >> > news:%235$BT%23F5EHA.2664@xxxxxxxxxxxxxxxxxxxxxxx
> >> >> Microsoft recommends using UTC time (universal Time
> > Coordinate)...similar
> >> > to
> >> >> the GMT concept. If you use that...
> >> >>
> >> >> DateTime.ToLocalTime()
> >> >> DateTime.ToUniversalTime()
> >> >>
> >> >> If you want GMT, you'll have to write your own utility class.
> >> >>
> >> >> -Jason
> >> >>
> >> >> "Bijoy Naick" <b_naick@xxxxxxxx> wrote in message
> >> >> news:eqpWn0F5EHA.3828@xxxxxxxxxxxxxxxxxxxxxxx
> >> >> >I have an events table which stores the time of each event - the time
> >> >> >and
> >> >> > assoicated timezone. Is there a way of converting this time into GMT
> >> > (with
> >> >> > support for DST).. some sort of function which accepts a time and
> >> > timezone
> >> >> > as parameters and returns the time in GMT?
> >> >> >
> >> >> >
> >> >>
> >> >>
> >> >
> >> >
> >>
> >>
> >
> >
>
>
>
.



Relevant Pages

  • Re: Getting Timezone Data
    ... I'm trying to devise a portable function for retrtieving timezone ... Note that the variable daylight does not indicate that daylight saving ...
    (comp.unix.programmer)
  • Re: Getting Timezone Data
    ... I'm trying to devise a portable function for retrtieving timezone ... Note that the variable daylight does not indicate that daylight saving ...
    (comp.unix.programmer)
  • RE: How to cycle SMTP?
    ... I want to be sure to get the TIMEZONE updated next month when Daylight ... Saving Time starts in the USA. ... For IBM-MAIN subscribe / signoff / archive access instructions, ...
    (bit.listserv.ibm-main)
  • Re: Obtaining timestamp of another timezone
    ... i want to obtain a timestamp of another timezone including daylight ... The Nonstop system is located in Europe (UTC +1). ... The other timezone is in USA. ... daylight saving time? ...
    (comp.sys.tandem)
  • Re: Cant compile SWI on FreeBSD
    ... MacOS X defines timezone() as a function. ... #define daylight _daylight ... +{time_t tloc; ...
    (comp.lang.prolog)