I have a need to be able to set the time and the timezone
on the device. I can set the time but have not been able
to set the timezone. Is there a easy way to this.
When I PInvoke SetTimeZoneInformation I get an Unsupported
exception. GetTimeZoneInformation seems to work OK.
On a related note: I have observed that I can launch the
clock.exe (using ShellExecuteEx) from my app and I am able
to set the time and timezone there, but my app only picks
up the time change. The timezone is not updated until I
stop and restart my application.
Is this a known thing and is there a work around without
having to stop and restart the application.
"Jeff Samuels" <samuels...@emeryworld.com> wrote in message
news:637d01c33ce2$477792c0$3101...@phx.gbl...
Thanks for the response.
Just had a look at the OpenNETCF library. I looked at the
Core.TIME_ZONE_INFORMATION class and the Core.TX_REG class
and I did not see a SetTimeZoneInformation (or similar)
methods for either of these. Am I missing something?
As for the other... It is not that my app needs to be
aware of a change to the timezone. Rather it is that when
the timezone does change the DateTime returned by
DateTime.Now (which returns the local time) does not show
the effect of the change. For example say it is 12:00pm
PDT and the tz is set to "Pacific". If I start my app and
subquently launch "clock" and change the tz to "Eastern".
I would expect DateTime.Now to return 3:00pm EDT. What I
get is 12:00pm PDT until I stop my App then restart. Then
I get the 3:00 pm EDT.
What I was wondering is there a way to get DateTime.Now to
show the correct local time without having to stop/start
my appplication.
Thanks again.
>.
>
OpenNETCF.WinAPI.Core.SetTimeZoneInformation();
Paul T.
"Jeff Samuels" <samuels...@emeryworld.com> wrote in message
news:104001c33cea$2eebe050$a401...@phx.gbl...
--
Chris Tacke, eMVP
Advisory Board Member
www.OpenNETCF.org
"Jeff Samuels" <samuels...@emeryworld.com> wrote in message
news:104001c33cea$2eebe050$a401...@phx.gbl...
It's a member of WinAPI.Core class
>
> As for the other... It is not that my app needs to be
> aware of a change to the timezone. Rather it is that when
> the timezone does change the DateTime returned by
> DateTime.Now (which returns the local time) does not show
> the effect of the change. For example say it is 12:00pm
> PDT and the tz is set to "Pacific". If I start my app and
> subquently launch "clock" and change the tz to "Eastern".
> I would expect DateTime.Now to return 3:00pm EDT. What I
> get is 12:00pm PDT until I stop my App then restart. Then
> I get the 3:00 pm EDT.
>
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);
In VB:
Imports System.Reflection
Dim tz as TimeZone = TimeZone.CurrentTimeZone
Dim fi as FieldInfo = tz.GetType().GetField("currentTimeZone",
BindingFlags.NonPublic OR BindingFlags.Static OR BindingFlags.Instance)
fi.SetValue(Nothing, Nothing)
Next time any time-formatting (or other timezone-dependent call is made), CF
will re-read current TZ info from OS