By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,199 Members | 1,551 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,199 IT Pros & Developers. It's quick & easy.

Daylight time wrong UTC time

P: n/a
I created a UTC clock using this:
UTCTime = MyTime.ToUniversalTime()
Now that we've turned the clocks ahead 1 hour for daylight savings time, the
clock is reporting the wrong UTC time. It is reporting UTC + 1 hour.
Is this a bug or is there a way I can querey for daylight time and make the
adjustment in my application?

Thanks.
Nov 21 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
This came up a few weeks ago in this newsgroup. Basically, MS Explorer shows
the correct time whereas the applications show MS Explorer time + 1 hour.
So, I guess it is an error

Crouchie1998
BA (HONS) MCP MCSE.
Nov 21 '05 #2

P: n/a
I think it is a bit imprudent to call it an error.

I, for example have never seen the bahaviour that has been described
regardless if the macine is in daylight saving time or not and also
regardless of whether or not daylight saving time has just cut in or out as
the case may be.

I think the appropriate course of action is for the original poster to
identify the specific condition that is causing the behaviour in the
configuration of the machine in question.
"Crouchie1998" <cr**********@spamcop.net> wrote in message
news:Oj**************@tk2msftngp13.phx.gbl...
This came up a few weeks ago in this newsgroup. Basically, MS Explorer
shows
the correct time whereas the applications show MS Explorer time + 1 hour.
So, I guess it is an error

Crouchie1998
BA (HONS) MCP MCSE.

Nov 21 '05 #3

P: n/a
Brett,

This gives me the correct UTC time (In the EU is summertime, as it is named
here started, with Easter).

MessageBox.Show(Now.ToUniversalTime.ToString)
I hope this helps,

Cor
Nov 21 '05 #4

P: n/a
Here's whole little thing for clarification...

Private Sub Timer1_Elapsed(ByVal sender As System.Object, ByVal e As
System.Timers.ElapsedEventArgs) Handles Timer1.Elapsed
MyTime = TimeOfDay
UTCTime = MyTime.ToUniversalTime()
TextBox1.Text() = UTCTime

End Sub

-Brett

"Stephany Young" wrote:
I think it is a bit imprudent to call it an error.

I, for example have never seen the bahaviour that has been described
regardless if the macine is in daylight saving time or not and also
regardless of whether or not daylight saving time has just cut in or out as
the case may be.

I think the appropriate course of action is for the original poster to
identify the specific condition that is causing the behaviour in the
configuration of the machine in question.
"Crouchie1998" <cr**********@spamcop.net> wrote in message
news:Oj**************@tk2msftngp13.phx.gbl...
This came up a few weeks ago in this newsgroup. Basically, MS Explorer
shows
the correct time whereas the applications show MS Explorer time + 1 hour.
So, I guess it is an error

Crouchie1998
BA (HONS) MCP MCSE.


Nov 21 '05 #5

P: n/a
I changed my querey of the current time from:
TimeOfDay() to Now()
This fixes the problem

Brett

"Brett Edman" wrote:
I created a UTC clock using this:
UTCTime = MyTime.ToUniversalTime()
Now that we've turned the clocks ahead 1 hour for daylight savings time, the
clock is reporting the wrong UTC time. It is reporting UTC + 1 hour.
Is this a bug or is there a way I can querey for daylight time and make the
adjustment in my application?

Thanks.

Nov 21 '05 #6

P: n/a
Well, that puts things in perspective.

Throw a couple of telltales in and you will see what is happening.

MyTime = TimeOfDay
Console.Writeline(MyTime.ToString())
UTCTime = MyTime.ToUniversalTime()
Console.Writeline(UTCTime.ToString())
TextBox1.Text() = UTCTime

Note what date part of the results shows.

From the documentation on the TimeOfDay property:

<quote>
Returns or sets a Date value containing the current time of day according to
your system.
</quote>

<furtherquote>
The Date data type includes date components. When returning the system time,
TimeOfDay sets these all to 1, so the returned value represents the first
day of the year 1.
</furtherquote>

When I execute you EXACT code I get 12:00:00 AM and the telltale shows
1/01/0001 12:00:00 AM. This timezone during daylight saving is UTC+13 hours
and the current time is about 10:30 AM. Subtracting 13 hours from 1/01/0001
10:30:00 AM would give 31/12/0000 9:30:00 PM but that is prior to the lowest
value allowed for a date and so it uses the lowest allowed as the result.

When I execute the following:

Dim MyTime As Date = CDate("01/01/0001 18:30:00")
Console.WriteLine(MyTime.ToString())
Dim UTCTime As DateTime = MyTime.ToUniversalTime()
Console.WriteLine(UTCTime.ToString())

I get:

1/01/0001 6:30:00 PM
1/01/0001 5:30:00 AM

Which is what I expect during daylight saving (UTC+13 hours). 1 January
falls within the daylight saving period down this end of the world.

When I modify the code to:

Dim MyTime As DateTime = CDate("30/06/0001 18:30:00")

I get:

30/06/0001 6:30:00 PM
30/06/0001 6:30:00 AM

Which, again, is what I expect during standard time (UTC+11 hours).

When I execute the first block of code (above) I notice a significant delay
betwen the first and second telltales being displayed. The delay is of about
the length that I observe when an exception is about to be thrown. I suspect
that some extra maths is going on here to ensure that the result is not
prior to the lowest value allowed for a date.

Given these findings, in my opinion, if the result of a date calculation
gives a result prior to the lowest value allowed for a date than a suitable
exception should be thrown rather than returning an erroneous value.

HOWEVER!

If you use:

Dim MyTime As DateTime = DateTime.Now
Console.Writeline(MyTime.ToString())
Dim UTCTime As DateTime = MyTime.ToUniversalTime()
Console.Writeline(UTCTime.ToString())
TextBox1.Text() = UTCTime.ToLongTineString()

You will always get the correct result in relation to your current timezone
(regardless of the daylight saving status) and your current culture.

I must say that it never would have occurred to me to try and convert a time
part to UTC because UTC is as much to do with the date part as it is the
time part. Maybe it's because, down this this end of the world, we spend at
least half our time having a different date than UTC does and perhaps that
makes us more aware of the need to make sure we use the correct techniques
when converting to and from UTC. In Western Europe, for example the date is
only different for, at most, 2 hours per day and that is when most sane
people are asleep and maybe the difference is not noticed anywhere as much.

I hope I have managed to make this a clear as mud and I'll see you on our
next 'date' :)
"Brett Edman" <Br********@discussions.microsoft.com> wrote in message
news:00**********************************@microsof t.com...
Here's whole little thing for clarification...

Private Sub Timer1_Elapsed(ByVal sender As System.Object, ByVal e As
System.Timers.ElapsedEventArgs) Handles Timer1.Elapsed
MyTime = TimeOfDay
UTCTime = MyTime.ToUniversalTime()
TextBox1.Text() = UTCTime

End Sub

-Brett

"Stephany Young" wrote:
I think it is a bit imprudent to call it an error.

I, for example have never seen the bahaviour that has been described
regardless if the macine is in daylight saving time or not and also
regardless of whether or not daylight saving time has just cut in or out
as
the case may be.

I think the appropriate course of action is for the original poster to
identify the specific condition that is causing the behaviour in the
configuration of the machine in question.
"Crouchie1998" <cr**********@spamcop.net> wrote in message
news:Oj**************@tk2msftngp13.phx.gbl...
> This came up a few weeks ago in this newsgroup. Basically, MS Explorer
> shows
> the correct time whereas the applications show MS Explorer time + 1
> hour.
> So, I guess it is an error
>
> Crouchie1998
> BA (HONS) MCP MCSE.
>
>


Nov 21 '05 #7

P: n/a
On Tue, 19 Apr 2005 10:04:05 -0700, "Brett Edman"
<Br********@discussions.microsoft.com> wrote:

I may be wrong, but I thought that UTC/GMT doesn't change with the
seasons, so here we are on BST at the moment or GMT +1

Doug Taylor
I changed my querey of the current time from:
TimeOfDay() to Now()
This fixes the problem

Brett

"Brett Edman" wrote:
I created a UTC clock using this:
UTCTime = MyTime.ToUniversalTime()
Now that we've turned the clocks ahead 1 hour for daylight savings time, the
clock is reporting the wrong UTC time. It is reporting UTC + 1 hour.
Is this a bug or is there a way I can querey for daylight time and make the
adjustment in my application?

Thanks.


Nov 21 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.