Re: Windows Time since When?

2004-01-06 Thread Rolf Kalbermatter
There is a bit of a discussion between me and a C programmer about the Time
Stamps in windows.

Windows itself has a number of time epoches.

First there is a 16 bit Windows API:
1) From the old times there is a DOS time which is really two 16 bit numbers with
bit packed interpretation (and behold: 2 seconds resolution)

The Win32 API has following time concepts:
2) The SYSTEMTIME is really a structure similar to the ANSI C structure tm
thus represents absolut time.

3) The FILETIME is a 64 bit value representing the number of 100 ns intervals
since January 1, 1601

Last there is the C runtime library time:
4) msvcrt or any other C runtime library one might use in a program has the
ANSI C implementation of time(), which is usually a signed long int with the
number of seconds since January 1, 1970, (and therefore will have a new
millenium problem sometime around 2037). The Visual C runtime really is just
a layer on top of the Win32 API.

LabVIEWs Get Date/Time in seconds does return the number of seconds since
midnight January 1, 1904 UTC and does this on different platforms in different
ways.
On Mac it simply requests the Mac time, then adjusting the returned local time
by the timezone offset.

On Windows it requests the SYSTEMTIME by calling GetSystemTime() then converts
this into a FILETIME with SystemTimeToFileTime() and after that subtracts the
difference between January 1, 1601 and January 1, 1904 in 100 nanoseconds
intervals and at the some time adjusts for the difference in interval length
by dividing the result with 10'000'000.

We are working on code that passes data with timestamps between LabVIEW and
C. The problem is LabVIEW’s “Get Date and Time in Seconds” is ‘since Jan 1,
1904.

My dusty C programming book states time_c is seconds since Jan 1, 1980 and
Unix is since Jan 1, 1970? The C programmer says it’s Jan 1, 1970.

According to ANSI the epoche of January 1, 1970 really is arbitrary although
quite popular and any C runtime implementation might choose to use a different
epoche.

That said; is there a Windows function I can call to get the windows time in
seconds since whenever it actually is? I suspect the LabVIEW function is the
“Platform Independent’ referenced time.

Well, to go from LabVIEW time to ANSI C time you basically just add the number
of LabVIEW seconds you would get by the LabVIEW Get Date/Time in seconds
function for midnight of most probably January 1, 1970 UTC. At least the
Visual C runtime library does use this epoche. If your C programmer uses a
different C compiler he will have to check in there.

You do need to watch out for timezone offsets however when trying to work in
such a way. The ANSI C documentation I have isn't really specific if the return
value of time() is in UTC or local time. Visual C however seems to return UTC.
You can try to avoid this by actually using gmtime and mktime.

Rolf Kalbermatter
CIT Engineering Nederland BVtel: +31 (070) 415 9190
Treubstraat 7H   fax: +31 (070) 415 9191
2288 EG Rijswijkhttp://www.citengineering.com
Netherlands mailto:[EMAIL PROTECTED]
 




Windows Time since When?

2004-01-05 Thread Jack Hamilton
There is a bit of a discussion between me and a C programmer about the Time
Stamps in windows.

We are working on code that passes data with timestamps between LabVIEW and
C. The problem is LabVIEW’s “Get Date and Time in Seconds” is ‘since Jan 1,
1904.

My dusty C programming book states time_c is seconds since Jan 1, 1980 and
Unix is since Jan 1, 1970? The C programmer says it’s Jan 1, 1970.

That said; is there a Windows function I can call to get the windows time in
seconds since whenever it actually is? I suspect the LabVIEW function is the
“Platform Independent’ referenced time.

Regards

Jack Hamilton
Hamilton Design
[EMAIL PROTECTED]
www.Labuseful.com
714-839-6375 Office