How to translate from UTC/GMT time to local time?
- From: Randall Parker <NOtechieSPAMpundit_please@xxxxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Fri, 16 Dec 2005 07:09:32 -0800
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?
.
- Follow-Ups:
- Re: How to translate from UTC/GMT time to local time?
- From: Joshua Flanagan
- Re: How to translate from UTC/GMT time to local time?
- Prev by Date: Re: How do I stop firewall from blocking my C# Web Browser?
- Next by Date: Accessing child values by string name
- Previous by thread: Re: How do I stop firewall from blocking my C# Web Browser?
- Next by thread: Re: How to translate from UTC/GMT time to local time?
- Index(es):
Relevant Pages
|