CRT time function depends on timezone?
From: Alex (sdfjkhsdkh_at_ksfjdkjwdfsklj.nowhere)
Date: 07/02/04
- Next message: Frank Rizzo: "Re: Need help with a problem"
- Previous message: Carl Daniel [VC++ MVP]: "Re: atof and VC7.1"
- Next in thread: Carl Daniel [VC++ MVP]: "Re: CRT time function depends on timezone?"
- Reply: Carl Daniel [VC++ MVP]: "Re: CRT time function depends on timezone?"
- Reply: Tim Robinson: "Re: CRT time function depends on timezone?"
- Messages sorted by: [ date ] [ thread ]
Date: Fri, 02 Jul 2004 10:57:22 -0400
It looks I've discovered something weird in CRT implementation
(MSVC5) of time function. The simple test (see below) shows time
going backwards. Between 2 "press any key" I've changed timezone to
the next one westward, windows correctly adjusted my local time to
one hour earlier, however the next time(0) call has returned the
value one hour earlier too. That was looking really strange, so I
took a look at the implementation of time in CRT and discovered that
it is indeed depends on the timezone.
The following comment in the source code explains why:
* Note: We cannot use GetSystemTime since its return is ambiguous. In
* Windows NT, in return UTC. In Win32S, probably also Win32C, it
* returns local time.
It sounds like a good reason to make it work incorrectly on Windows
NT. Ok, it's easy enough to write your own function to get UTC time
through GetSystemTime, MSDN says that it is available on
"Windows XP, Windows 2000 Professional, Windows NT Workstation,
Windows Me, Windows 98, or Windows 95."
I don't need Win32S, but what is Win32C? And why the author didn't
know what GetSystemTime returns there?
Alex.
===================================================
#include <time.h>
#include <conio.h>
int main(int argc, char** argv)
{
clock_t c0, c1;
time_t t0, t1;
c0 = clock();
t0 = time(0);
printf("t = %d\nc = %d\nPress any key...\n",t0,c0);
getch();
c1 = clock();
t1 = time(0);
printf("t = %d\nc = %d\nPress any key...\n",t1,c1);
getch();
return 0;
}
=========================================================
U:\test>get-time-test
t = 1088782360
c = 0
Press any key...
t = 1088778768
c = 8593
Press any key...
- Next message: Frank Rizzo: "Re: Need help with a problem"
- Previous message: Carl Daniel [VC++ MVP]: "Re: atof and VC7.1"
- Next in thread: Carl Daniel [VC++ MVP]: "Re: CRT time function depends on timezone?"
- Reply: Carl Daniel [VC++ MVP]: "Re: CRT time function depends on timezone?"
- Reply: Tim Robinson: "Re: CRT time function depends on timezone?"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|