SetTimeZoneInformation, SetLocalTime, DateTime.Now not sync

S

swc

I have been reading all the posts, and after testing it I am still very
confused.
and my findings seems to be a bit different. and I was wondering if it's the
difference
between different .netcf versions.
(I am running it under the ARM emulator, so maybe that's the difference
also)

I am using a custom build CE 5.0, .NETCF 2.0 with all the QFE upto December
2008.

Here's what I find: as soon as I call pinvoked SetTimeZoneInformation(), the
DateTime.Now's time is actually corrected
according to the new timezone info, but pinvoked GetLocalTime() call's time
did not change.
Also the clock control panel's time did not change, but the timezone changed
to the one
SetTimeZoneInformation() did.
I also find that the .net's TimeZone (function call/property) is the old
time zone until the application is restarted, which
is what all the threads were saying about the DateTime.Now is using the old
timezone.


Now the question is, do I have to set the date and time using SeLocalTime()
with with the difference in the
changed timezone? or is SetTimeZoneInformation suppose to update the time
also.
but if I update the time using SetLocalTime(), the DateTime.Now would also
change making it incorrect.

If I have to call setTimeZoneInformation and setlocaltime that would be
whatever the post is doing and
I can't use the DateTime.Now in my app. and looks like in either case, I
have to replace DateTime.Now with SetLocalTime.
 
S

swc

http://groups.google.com/group/micr...gst&q=setTimeZoneInformation#2eba94e80442a879

I have re-read some post in more detail and found the above link that
mentioned the current timezone can be
updated in .NETCF using reflection.
The post is dated in 2003 and some post I have find in 2007 still says the
DateTime.Now have problem
because the current timezone in CF is not updated when you do a
SetTimeZoneInformation() using pinvoke.

from Alex Feinman [MVP]
"The current timezone information is kept in a private static member of the
TimeZone class called currentTimeZone. It is initialized once and then
reused. The way to force its refresh is to set it to null:


using System.Reflection;
FieldInfo fi = typeof(TimeZone).GetField("currentTimeZone",
BindingFlags.NonPublic|BindingFlags.Static|BindingFlags.Instance);
fi.SetValue(null, null);

"
with the current timezone updated in .NET, the DateTime.Now works correctly
and in sync
with GetLocalTime() pinvoke.

I still have to set the time after I did a SetTimeZoneInformation(), so I'm
guessing that's what
it needs to update the timezone.
 

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