Re: UTCNow <> GMT
- From: "Stephany Young" <noone@localhost>
- Date: Mon, 21 Jul 2008 19:02:53 +1200
Unless you are working in the actual GMT timezone, (that is The United Kingdom of Great Britain and Northern Ireland, The Republic of Ireland and Portugal), then forget about GMT.
If you need to deal with timestamps all around the world then you have 2 choices.
1. Store your timestamps as 'local time' in relation to the defined timezone of the computer along with some information about the timezone. If you do this you need to store the timezone information in such a manner that a 'local time' in say, Brazil, can be correctly displayed as a 'local time' in, say, India. This entails converting the Brazilian value to UTC and then converting the result to the appropriate Indian value.
2. Store your timestamps as Universal Time Coordinated (UTC). This requires only one conversion when the value is finally displayed. For all other purposes all values will automatically be 'in sync'.
To obtain a value in UTC, simply use the DateTime.UtcNow method.
To display a UTC value in local time, simply use the myvalue.ToLocalTime method.
At present, it is 7:00 PM on July 21 2008 where I am.
Dim myvalue = DateTime.UtcNow()
gives 7:00 AM on July 21 2008.
If I pass that value to you and you execute:
Dim mylocal = myvalue.ToLocalTime()
you will get 9:00 AM on July 21 2008.
All you have to know is that any timestamp value that I pass to you is in UTC.
As to people travelling and not adjusting their timezones, then
myvalue.ToLocalTime()
will convert based on the timezone that the machine is set to.
If they are in India and the timezone of the machine is set to Brazil the the result will be converted to Brazilian local time.
"Olaf Rabbachin" <Olaf_NoSpam@xxxxxxxxxxxx> wrote in message news:%23B%23Yzuv6IHA.2336@xxxxxxxxxxxxxxxxxxxxxxx
Hi,
Nick wrote:
Any idea how I get the time in GMT with VB.NET? Obviously UtcNow is
*not* an option.
I for one am probably in a similar situation. I have an application that is
about to be used by field engineers all over the planet and uses a
WebService to synchronize data with a server in Germany. Even worse, those
engineers travel around the world and stay for a couple of days in one
location (probably not changing their PCs timezone to match the one they
are in) and a couple of months in another (most probably setting the time
zone).
Every record has its own timestamps (created, updated, deleted, last
sync'ed) and the sync-process of course heavily depends on those timetamps.
I thus need to find an invariant format in which timestamps are being
stored (UTC/GMT). The application would have to convert values retrieved
from the database on each PC according to the regional-/time-settings (and
vice versa).
I'm not sure what *you* are trying to accomplish, but I stumbled over ...
my.Computer.Clock.GmtTime
my.Computer.Clock.LocalTime
Using DateDiff on that would allow me to "convert" the timestamps as I
could simply do a DateDiff to get the difference in minutes and apply that
to my timestamps.
That said, I don't really need the DaylightSavings, just the difference to
a sort of global baseline such as GMT/UTC.
BTW - the description of the my.Computer.Clock.GmtTime property reads "Gets
a Date object that contains the current local date and time on the
computer, expressed as a UTC (GMT) time.". According to the information I
read here and at other places it seems that there really is a difference,
but in VS.Net both terms are used equivalently, hence I'm confused, too.
Any insights and/or hints appreciated here as well!
Cheers,
Olaf
.
- Follow-Ups:
- Re: UTCNow <> GMT
- From: Olaf Rabbachin
- Re: UTCNow <> GMT
- From: Nick
- Re: UTCNow <> GMT
- References:
- UTCNow <> GMT
- From: Nick
- Re: UTCNow <> GMT
- From: Olaf Rabbachin
- UTCNow <> GMT
- Prev by Date: Re: UTCNow <> GMT
- Next by Date: Re: Need Table and Subtable in RDLC
- Previous by thread: Re: UTCNow <> GMT
- Next by thread: Re: UTCNow <> GMT
- Index(es):
Relevant Pages
|