Well, that puts things in perspective.
Throw a couple of telltales in and you will see what is happening.
MyTime = TimeOfDay
Console.Writeli ne(MyTime.ToStr ing())
UTCTime = MyTime.ToUniver salTime()
Console.Writeli ne(UTCTime.ToSt ring())
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.WriteLi ne(MyTime.ToStr ing())
Dim UTCTime As DateTime = MyTime.ToUniver salTime()
Console.WriteLi ne(UTCTime.ToSt ring())
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.Writeli ne(MyTime.ToStr ing())
Dim UTCTime As DateTime = MyTime.ToUniver salTime()
Console.Writeli ne(UTCTime.ToSt ring())
TextBox1.Text() = UTCTime.ToLongT ineString()
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********@dis cussions.micros oft.com> wrote in message
news:00******** *************** ***********@mic rosoft.com...
Here's whole little thing for clarification.. .
Private Sub Timer1_Elapsed( ByVal sender As System.Object, ByVal e As
System.Timers.E lapsedEventArgs ) Handles Timer1.Elapsed
MyTime = TimeOfDay
UTCTime = MyTime.ToUniver salTime()
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.
"Crouchie19 98" <cr**********@s pamcop.net> wrote in message
news:Oj******** ******@tk2msftn gp13.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.
>
>