Daylight time wrong UTC time

G

Guest

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

Crouchie1998

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

Stephany Young

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

Cor Ligthert

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
 
G

Guest

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
 
G

Guest

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

Brett
 
S

Stephany Young

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' :)
 
D

Doug Taylor

On Tue, 19 Apr 2005 10:04:05 -0700, "Brett Edman"

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
 

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