UTCNow <> GMT

N

Nick

Hi there

I'm trying to use the IsDaylightSavingTime property of the datetime
object.

The PC I am using is in GMT,

DateTime.Now.IsDaylightSavingTime() returns true
DateTime.UtcNow.IsDaylightSavingTime() returns false

The times also differ by 1 hour.

As far as I was aware, GMT = UTC

http://www.dxing.com/utcgmt.htm

But quite evidently .NET thinks otherwise. I desperately need a
resolution to this.

Any idea how I get the time in GMT with VB.NET? Obviously UtcNow is
*not* an option.

Thanks in advance.

Nick.
 
N

Nick

Hi there,

A solution for anyone interested,

http://www.codeproject.com/KB/vb/TimeZoneInfo.aspx

TimeZoneInfo.FromStandardName("GMT Standard
Time").IsDaylightSavingTime()

This seems to be working fine, unfortunately I can't use the
TimeZoneInfo classes in .net 3.5 as i'm using .net 2.0 and don't think the
hassle of updating is worth it.

Please correct me if I'm wrong but this should do the trick...

Nick.
 
S

Stephany Young

You obviously didn't read the web page at that link very well.

It states, in so many words, that UTC used to be called GMT. That means that
at some point in the past it was called GMT but is not anymore.

When it comes to a Windows OS, GMT is a time zone and UTC is not. UTC is a
concept which forms the base of all time zones.

You must remember that to the Windows OS, a time zone is more that just a
slice of the world. It is actually a slice of the world where everywhere
within that slice share the same Dayligt Saving rules.

For part of the year the time in the GMT time zone is the same time as that
represented by UTC, but for rest of the year, (Daylight Saving), the GMT
time zone is 1 hour ahead of UTC.

If you want to get the local date/time where you are the you use
DateTime.Now. Note that DateTime.Now is always represented in your current
time zone and is always adjusted for the daylight saving rules that apply to
that time zone.

If you want to get a date/time that is unambiguous anywhere in the world
then use DateTime.UtcNow.
 
N

Nick

Hi Stephany,

Thanks for the info, you obviously didn't read my follow up reply very
well also.

It has a solution to said problem as UtcNow is *not* a solution which I
said in my first post.

Thanks.

Nick.
 
N

Nick

lol! and you're right, I scan read a few pages that said GMT was UTC and
just posted the first link that had the most text on.
 
R

Rory Becker

The PC I am using is in GMT,

Are you sure of this?
DateTime.Now.IsDaylightSavingTime() returns true
DateTime.UtcNow.IsDaylightSavingTime() returns false
The times also differ by 1 hour.

As far as I was aware, GMT = UTC

Likewise I believe this to be true, but If you're in the uk right now for
instance, then you're actually in BST not GMT
 
C

Cor Ligthert[MVP]

Sthephany,

Sorry, but what you wrote is in my idea wrong: << UTC is a concept which
forms the base of all time zones >>.

Greenwich Mean Time is what UTC is based on. It is one of the few
measurements standards that is used worldwide invented by the British. As
you are once in Europe, you can go to the Thames river and you can see a
nice house in Greenwhich where is the machinery that holds the UTC time.

(As I recongnize the way of writting, it is very near where Nick lives).

Cor
 
S

Steven Cheng [MSFT]

Hi Nick,

I agree that UTC is not 100% match to the GMT you expected as GMT is a
timezone while UTC is more likely a baseline for sharing time amone world.
For your scenario, what's your application's actual requirement? So far in
..net framework, we cannot set a certain application process or thread as a
particular timezone, if you want to deal with datetime as the GMT zone, the
target machine's regional setting and timezone setting should match that.
then, you can just use the local time.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.


--------------------
 
O

Olaf Rabbachin

Hi,
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
 
S

Stephany Young

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.
 
N

Nick

Hi Steven,

It was a bit of an awkward situation tbh. I'm reading some timing
information from the bottom of a web page that reads, "All times are GMT+1.
The time is now xxx". Unfortunately this wasn't the case as the timing was
1 hour out, but previously before the last clock change the times matched,
so I figured it was daylightsavings. Thankfully I had a line of code to
compensate already written, but the only problem being was that it didn't
know it was in daylight savings.

The class of code project helped solve that problem. It's slightly odd
that the site refers to GMT no matter where you are in the world, but then
it's something that could be worked around so all is well!

Nick.
 
N

Nick

Hi Rory,
Are you sure of this?

Uhh well I thought I was until you said...
Likewise I believe this to be true, but If you're in the uk right now for
instance, then you're actually in BST not GMT

That's strange, I wasn't aware that the timezone name changed when in
summertime? Learn something new everyday LOL!

With that said the class from the code project worked well with the code I
posted and knows that we are in summer time so all is well on that front.

Nick.
 
N

Nick

Hi Stephany,
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.

Unfortunately that rule, although correct to a certain extend, unless
the code you are trying to integrate has done likewise, you are onto a loss
from the word go. The site I'm parsing refers to a GMT offset no matter
where you are in the world but does not compensate for daylight savings,
hence my predicament.

If the site had been code as you suggest, using UTC throughout until
display time, when you convert to local them, my problems wouldn't have
existed in the first place. But never mind, it's all working great now, and
I appreciated your information even though that might not have come across
in my reply.

Nick.
 
G

Göran Andersson

Cor said:
Sthephany,

Sorry, but what you wrote is in my idea wrong: << UTC is a concept
which forms the base of all time zones >>.

I don't understand your idea... That is exactly what it is.

"Time zones around the world are expressed as positive or negative
offsets from UTC. Local time is UTC plus the time zone offset for that
location, plus an offset (typically +1) for daylight saving time, if in
effect. UTC replaced Greenwich Mean Time on 1 January 1972 as the basis
for the main reference time scale or civil time in various regions."

http://en.wikipedia.org/wiki/Coordinated_Universal_Time

Greenwich Mean Time is what UTC is based on.

Maybe in a historical sence, as UTC replaced GMT, but not in any
practical sence.

"Greenwich Mean Time (GMT) is a term originally referring to mean solar
time at the Royal Observatory in Greenwich, London. It is now often used
to refer to Coordinated Universal Time (UTC) when this is viewed as a
time zone"

"UT1, introduced in 1928, represents earth rotation time. Leap seconds
are added to or subtracted from UTC to keep it within 0.9 seconds of UT1."

http://en.wikipedia.org/wiki/Gmt

So, GMT is based on UTC, which is based on UT1.
 
R

Rory Becker

Hello Nick,
That's strange, I wasn't aware that the timezone name changed when in
summertime? Learn something new everyday LOL!

If I understand things correctly GMT and UTC are static which is to say they
do not change with respect to any Summer time / Daylight savings time.

However the Uk observes "British summer time (BST)" as such ,at the start
of the summer, the Uk shifts from GMT/UTC into BST. If you are in the Uk
and your computer notices this then when you ask for "Now" then you will
be given the Local time (ie BST) and therefore explains why the following
happends...
-------------------------------------------------------------
DateTime.Now.IsDaylightSavingTime() returns true
DateTime.UtcNow.IsDaylightSavingTime() returns false
-------------------------------------------------------------

Again, if I understand things correctly, a UTC Time should never return true
for "IsDaylightSavingTime"
Whilst "Now" will will return true if the current Local is currently experiencing
Daylight savings. At the moment the UK is and so it returns true.


I hope this helps
 
G

Göran Andersson

Rory said:
Hello Nick,


If I understand things correctly GMT and UTC are static which is to say
they do not change with respect to any Summer time / Daylight savings time.

For UTC that is certainly true.

GMT is mostly used as a base for time zones, for example (GMT+1).
Depending on whether daylights savings time is active or not, this can
mean be (UTC+1) or (UTC+2). Therefore, the meaning of GMT would be
different depending on whether you mean GMT or (GMT+0), the first
meaning UTC and the second meaning the Greenwich time zone. As "+0"
isn't even spelled out when used as a time zone, the meaning depends on
the situation...
the Uk and your computer notices this then when you ask for "Now" then
you will be given the Local time (ie BST) and therefore explains why the
following happends...

Yes, that is correct.
 
R

Rory Becker

Hello Göran,
GMT is mostly used as a base for time zones, for example (GMT+1).
Depending on whether daylights savings time is active or not, this can
mean be (UTC+1) or (UTC+2).

Can you point to some reference from which you gather this...?

From http://www.timeanddate.com/library/abbreviations/timezones/eu/gmt.html

"GMT is in the same time zone as Coordinated Universal Time (UTC)"

There are no exceptions listed.

GMT = UTC = BST-1
GMT+1 = UTC+1 = BST
GMT+2 = UTC+2 = BST+1

The only issue here is that "Now" returns the Localized time. So if your
local is observing BST, then "Now" returns BST and you need to be aware that
simply being in the uk (where Greenwich is) is not enough to say you are
in GMT as the uk observes BST at suitable points during the year instead.
 
G

Göran Andersson

Rory said:
Hello Göran,


Can you point to some reference from which you gather this...?

"Greenwich Mean Time (GMT) is a term originally referring to mean solar
time at the Royal Observatory in Greenwich, London. It is now often used
to refer to Coordinated Universal Time (UTC) when this is viewed as a
time zone"

http://en.wikipedia.org/wiki/Gmt
From
http://www.timeanddate.com/library/abbreviations/timezones/eu/gmt.html

"GMT is in the same time zone as Coordinated Universal Time (UTC)"

UTC is not a time zone, it's the universal time. Time zones are defined
relative to UTC.
There are no exceptions listed.

GMT = UTC = BST-1
GMT+1 = UTC+1 = BST
GMT+2 = UTC+2 = BST+1

A time zone is a geographical area, so BST isn't actually a time zone.
It's just a name for the time used in a time zone a part of the year.
When the people in the zone switches from using BST to GMT, they are
still in the same time zone...
 
R

Rory Becker

Hello Göran,

I think we are outside the OP original point by now however.....
"Greenwich Mean Time (GMT) is a term originally referring to mean
solar time at the Royal Observatory in Greenwich, London. It is now
often used to refer to Coordinated Universal Time (UTC) when this is
viewed as a time zone"

http://en.wikipedia.org/wiki/Gmt

I meant for you to supply a reference as to how GMT+1 could in some cases
be UTC+1 and in other cases be UTC+2. I do not see how this can be the case.
The uk switches from GMT to BST and back again, but GMT itself and UTC remain
static and (near enough) identical to one another. Is this not so?

GMT+1 can never be the same as UTC+2.

Now that I reread what you wrote, I am not sure I interpreted what you said
correctly. I'm fairly sure we agree. Sorry to anyone who might have become
confused by what I have said :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top