Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

SetLocalTime api

1 view
Skip to first unread message

Empi

unread,
Oct 6, 2008, 6:38:53 AM10/6/08
to
Hi,

I'm using SetLocalTime API in order to update an iPaq's clock according to
user's request.

Whenever the user updates the time, I should update another device's clock
using rs232.

I noticed the following:
When changing from summer to winter and the other way around (e.g. 1 sept 08
<==> 1 Jan 08),
DateTime.Now returns 1 hour less / more than the hour I set using the
setlocal time...
e.g. when moving from Sept to Jan it moves back 1 hour, and add an hour when
moving from Sept to Jan...
DateTime.Now that suppose to return local time as was set returns +- 1 hour.

More over, this is happening when Regional settings are set to Pacific US
(G.M.T -8) and doesn't happen
when using G.M.T + 2 (Cairo for example).

1- Why DateTime.Now return something else than what was set by setlocaltime?
2- How can I be sure that GMT + 2 will work for all dates?
3- I've read that SetLocalTime need to be called twice in order to fix a
relevant bug (it update daylight saving according to the original date and
not the new one). I tried it, but it didn;'t solve the problem.

Any clues?


Thank you very much.

Empi


Paul G. Tobey [eMVP]

unread,
Oct 6, 2008, 12:18:07 PM10/6/08
to
It's Daylight Saving Time (or Summer Time, or any number of other terms used
to indicate that, at some times of the year, the clocks are moved forward or
backward an hour). You can look up Daylight Saving Time on something like
Wikipedia, if you want a history and more-detailed explanation. Various
parts of the world do this at various times of the year. You need to take
suitable action based on what's right for your overall system. Perhaps you
should be using SetSystemTime, rather than SetLocalTime, or maybe you should
allow for the automatic Daylight Saving Time shift, and then change the
local time a second time (I don't think this is a bug; it's much more-likely
that you'd want the automatic DST transition to happen, than it is that
you'd be calling SetLocalTime over and over and over and each time setting
it such that the DST adjustment has to happen; that seems much more like a
weird test case, not a real usage scenario). You'll have to tell us more
about *why* you're calling SetLocalTime() for us to really address what you
should do...

Paul T.

"Empi" <mpe...@softstart.co.il> wrote in message
news:eG5Z8%235JJH...@TK2MSFTNGP04.phx.gbl...

Empi

unread,
Oct 6, 2008, 2:53:14 PM10/6/08
to
Hi and thanks...

Yes. I do know what daylight saving is.

I found no option on the iPaq 2190 to enable/disable daylight saving.

I simply need an option for the user to set system's date and time using my
application.

"Paul G. Tobey [eMVP]" <p space tobey no spam AT no instrument no spam DOT
com> wrote in message news:O1CSf88J...@TK2MSFTNGP03.phx.gbl...

Paul G. Tobey [eMVP]

unread,
Oct 6, 2008, 3:04:14 PM10/6/08
to
No, Windows Mobile has no option exposed to disable it. I'm not sure that
the option found on generic Windows CE would work or not (and that's, as I
said, the wrong way to address this, best I can tell). You could try to
look up that registry entry for generic Windows CE on MSDN, probably in the
time server registry settings or maybe the shell registry settings.

OK, so you're doing exactly what the Date/Time Control Panel applet does, so
you shouldn't expect to be able to do better than what it does. I presume
that you see the same shift of time when you change it there, right? You
could, I suppose, check the return value of GetTimeZoneInformation() before
and after the time/date change to see whether you've shifted from daylight
time to standard time or vice versa and then set the time again to avoid the
hour jumping. If you change the date/time and the result of
GetTimeZoneInformation() is the same before and after, I don't think you
have to do anything.

Paul T.

"Empi" <mpe...@softstart.co.il> wrote in message

news:OcvCMT%23JJH...@TK2MSFTNGP05.phx.gbl...

Empi

unread,
Oct 6, 2008, 3:39:34 PM10/6/08
to
Thanks!


"Paul G. Tobey [eMVP]" <p space tobey no spam AT no instrument no spam DOT

com> wrote in message news:uL5%23TZ%23JJH...@TK2MSFTNGP02.phx.gbl...

Empi

unread,
Oct 7, 2008, 11:58:59 AM10/7/08
to
Isn't it "easier" just to set it twice?

If I need to call 2 api's anyway...

BTW,

calling setlocaltime twice doesn't solve it...

I'm trying now to set a delay between those 2 calls, maybe it is related to
it.

This daylight saving is sometimes *#lsdqj2341%#$ !
I wonder if it saves as much as we think or maybe all these savings are
going to programmers like me that must handle
it... ;-)

Thanks.


Empi


"Paul G. Tobey [eMVP]" <p space tobey no spam AT no instrument no spam DOT

com> wrote in message news:uL5%23TZ%23JJH...@TK2MSFTNGP02.phx.gbl...

Paul G. Tobey [eMVP]

unread,
Oct 7, 2008, 12:12:08 PM10/7/08
to
Other applications could be waiting on that event. It might be a good idea
to set the time only as often as you actually need to. It just depends on
what those other applications might do in response to a time change.

It takes time for the time service or the shell, depending on which version
of Windows CE we're talking about, to actually detect the adjustment,
calculate whether the new time should be DST or standard time, figure out if
that means a change from the current state of that flag and, if so, change
the clock by the right amount. There are various things that you might try:
delay, as you're doing now, detect the time server's call to change the time
and react to that, etc.

Ah, you live somewhere that it is used, huh? I live in Arizona, which long
ago decided that we have plenty of daylight, thank you very much. Our time
doesn't ever shift. I'm all in favor of dumping it.

Paul T.

"Empi" <mpe...@softstart.co.il> wrote in message

news:u7C6dWJ...@TK2MSFTNGP04.phx.gbl...

Empi

unread,
Oct 7, 2008, 12:20:15 PM10/7/08
to
Well than... I'm moving to Arizona...
Hope the company will agree to shift with me.

:-D

Thanks a lot.

Empi

"Paul G. Tobey [eMVP]" <p space tobey no spam AT no instrument no spam DOT

com> wrote in message news:u7%23CydJK...@TK2MSFTNGP05.phx.gbl...

Paul G. Tobey [eMVP]

unread,
Oct 7, 2008, 12:28:26 PM10/7/08
to
Don't see why not. Weather probably not that different. ;-)

Paul T.

"Empi" <mpe...@softstart.co.il> wrote in message

news:uOcBXiJ...@TK2MSFTNGP03.phx.gbl...

0 new messages