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

Time stamp

13 views
Skip to first unread message

Kuan Huang

unread,
Feb 16, 2002, 10:13:50 AM2/16/02
to
I would like to develop an win32 application that retrieve the time stamp
from server. I do not wish the users change the data and time from their
desktop. How do I accomplishe this? It's looks very eazy to do it by web
technology such as ASP. but, how do I accomplish it in win32 application?

Thanks,

Kuan Huang


James Ingram

unread,
Feb 16, 2002, 11:22:37 AM2/16/02
to
On Sat, 16 Feb 2002 10:13:50 -0500, "Kuan Huang"
<kuan...@worldnet.att.net> wrote:

>I would like to develop an win32 application that retrieve the time stamp
>from server.

Simply pop a COM object on the server that retirns the current
Date/Time. Call that component from the client and set the date/time
on the client with the value you get.

It will be *slightly* innacurate because of the time it takes for the
communications, so all your clients will be a few milliseconds off,
and some may even be half a second if your network is very slow when
they do it.

>I do not wish the users change the data and time from their
>desktop. How do I accomplishe this? It's looks very eazy to do it by web
>technology such as ASP. but, how do I accomplish it in win32 application?

No idea. That's an O/S config issue. Win98 - forget it, probably.
NT - may be possible, look at user privilidges and see if you can
disable it.

Better to have an EXE that checks the time against the server on a
regular basis and resets it if it is out (once every second if you're
paranoid; no user can click THAT fast)!

There are many tools available on the net for clock-syncing. Your
best bet is to use one of them. It is such an old, established
process that there ought to be decent freeware ones available, and all
you need is an NT box which is a time server.


James

Joe "Nuke Me Xemu" Foster

unread,
Feb 16, 2002, 8:37:51 PM2/16/02
to
"James Ingram" <james.hip...@btinternet.hippo.com> wrote in message <news:6qtt6u8got77a5be3...@4ax.com>...

> On Sat, 16 Feb 2002 10:13:50 -0500, "Kuan Huang"
> <kuan...@worldnet.att.net> wrote:
>
> >I would like to develop an win32 application that retrieve the time stamp
> >from server.
> Simply pop a COM object on the server that retirns the current
> Date/Time. Call that component from the client and set the date/time
> on the client with the value you get.
>
> It will be *slightly* innacurate because of the time it takes for the
> communications, so all your clients will be a few milliseconds off,
> and some may even be half a second if your network is very slow when
> they do it.

One could improve things a bit by timing how long the call takes,
perhaps using QueryPerformanceCounter, and adjusting the time by
half of the duration of the remote call. You'll need to twiddle
the system clock at least twice in any case, due to an old bug:

URL:http://support.microsoft.com/default.aspx?scid=kb;;q234735

> Better to have an EXE that checks the time against the server on a
> regular basis and resets it if it is out (once every second if you're
> paranoid; no user can click THAT fast)!

Wouldn't it be better to just compare the clock with timeGetTime
or GetTickCount every so often? If they drift too far out of sync,
then checking the clock against the time source is called for.
Also watch out for time-zone issues. Here's an easy way to base
the timestamps on UTC with sub-second precision:

Private Declare Sub GetSystemTime Lib "Kernel32" (lpSystemTime As SYSTEMTIME)
Private Declare Sub GetLocalTime Lib "Kernel32" (lpSystemTime As SYSTEMTIME)

Private Type SYSTEMTIME
wYear As Integer
wMonth As Integer
wDayOfWeek As Integer
wDay As Integer
wHour As Integer
wMinute As Integer
wSecond As Integer
wMilliseconds As Integer
End Type

Private Const ToHour = #2:00:00 AM# - #1:00:00 AM#
Private Const ToMinute = #12:01:00 AM# - #12:00:00 AM#
Private Const ToSecond = #12:00:01 AM# - #12:00:00 AM#
Private Const ToMilliSec = ToSecond / 1000

Public Function RightNow(Optional ByVal LocalTime As Boolean = False) As Date
Dim ST As SYSTEMTIME

If LocalTime Then GetLocalTime ST Else GetSystemTime ST

RightNow = ((((ST.wMilliseconds * ToMilliSec) + ST.wSecond * ToSecond) _
+ ST.wMinute * ToMinute) + ST.wHour * ToHour) _
+ DateSerial(ST.wYear, ST.wMonth, ST.wDay)
End Function

--
Joe Foster <mailto:jlfoster%40znet.com> Sign the Check! <http://www.xenu.net/>
WARNING: I cannot be held responsible for the above They're coming to
because my cats have apparently learned to type. take me away, ha ha!


James Ingram

unread,
Feb 16, 2002, 11:47:09 PM2/16/02
to
On Sat, 16 Feb 2002 17:37:51 -0800, "Joe \"Nuke Me Xemu\" Foster"
<j...@bftsi0.UUCP> wrote:

>One could improve things a bit by timing how long the call takes,
>perhaps using QueryPerformanceCounter, and adjusting the time by
>half of the duration of the remote call.

Yeah :) But what's a second between friends...?


Thanks for the usful code.. archived for if I ever need it, nach :)

Jamesm

0 new messages