How to translate from UTC/GMT time to local time?



Suppose one has a database of UTC times that are from different dates in the past. The problem with translating those times to a local time is that one does not know for each UTC time whether the local time at that same moment had daylight savings time in effect.

If one has a local time it is easier to translate it into UTC time. One can get the UTC time and one can even calculate the number of hours difference between them as follows:

System.DateTime CurrTime = System.DateTime.Now;
System.DateTime CurrUTCTime = CurrTime.ToUniversalTime();
long DiffFactorTicks = CurrUTCTime.Ticks - CurrTime.Ticks;
// NumTicksDiff
// 100 nanosecond ticks: 10,000,000 ticks per second?
double DiffFactorSeconds = DiffFactorTicks/10000000;
double DiffFactorHours = DiffFactorSeconds/3600; // this'll be positive and will be subtracted from date/times.


If one subtracts DiffFactorHours from a UTC time one will get one's local time. But that ONLY works if the UTC/local difference is the same as the current difference.

I do not see how to start with a UTC time and get to a local time because I do not see how starting with a UTC time to find out what the hours difference is to local. The problem is that daylight savings time might or might not be in effect.

Also, how to go to a local time that is other than the local time of the server that you happen to be running?
.




Relevant Pages

  • Re: [SLE] NTP Server - US Daylight Savings Time
    ... the system gives you the local time, calculated from the UTC time + ... depending on their local adjustments: ... Dos/windows expect the CMOS clock to be at local time instead... ...
    (SuSE)
  • Re: How convert GMT to LocalTime in Access 2003
    ... Dim udtTZI As TimeZoneInfo ... 'The bias is the difference, in minutes, ... 'between UTC time and local time. ...
    (microsoft.public.access.queries)
  • Re: [opensuse] Panel problems
    ... The date command, by default, shows local time. ... I think it can also be used to set utc time. ... set it in the bios myself first. ...
    (SuSE)
  • Re: Best practice for TOD clock
    ... One GREAT reason for using UTC time with local time ... > local applications that log with local time) for one hour in the fall. ... > duplicate timestamps if the timestamps are using UTC time. ... If "the meridian" you mention is the Greenwich meridian, ...
    (bit.listserv.ibm-main)
  • Re: Knode showing incorrect date
    ... PerfectReign wrote: ... >> What your program dies is translating the time in the article to your ... >> local time, so it looks correct for you. ...
    (alt.os.linux.suse)