Re: UTCNow <> GMT



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

.



Relevant Pages

  • Re: timezone setting
    ... afaik the Linux kernel keeps the systemtime in UTC. ... corrected by the value in /etc/timezone to the local time. ... whatever timezone you want with all the historic idiosyncracies of each ... It is a copy of one of the zoneinfo files found ...
    (Ubuntu)
  • RE: Best practice for TOD clock
    ... returns the UTC time. ... local applications that log with local time) for one hour in the fall. ... duplicate timestamps if the timestamps are using UTC time. ... For IBM-MAIN subscribe / signoff / archive access instructions, ...
    (bit.listserv.ibm-main)
  • Setting windows/win32 timezone from python
    ... an arbitrary timezone. ... To do this on UNIX is relatively straightforward by setting the TZ ... the mapping from utc -> local time won't have the correct ...
    (comp.lang.python)
  • Re: Can or should the NTP protocol eventually serve timezone data?
    ... How you torture UTC to get your preferred local time is entirely up to you. ... Kludging local timezone conversions into the NTP protocol somehow would be a nightmare if you could persuade anyone to do it! ...
    (comp.protocols.time.ntp)
  • Re: solar local time
    ... To convert a time in UTC to a local time in the America/New_York timezone, ... include TZInfo ... Note that the Time returned will look like it is UTC. ...
    (comp.lang.ruby)