CRT time function depends on timezone?

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Alex (sdfjkhsdkh_at_ksfjdkjwdfsklj.nowhere)
Date: 07/02/04


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...



Relevant Pages

  • Date and time wouldnt show up in windows xp?
    ... My OS is windows xp sp2 and just now I realized there is something ... wrong with the date and time function. ... I tried clicking on the clock ...
    (microsoft.public.windowsxp.help_and_support)
  • high resolution time function?
    ... i need a high resolution c/c++ time function. ... i need something like QueryPerformanceCounter on windows. ...
    (comp.os.linux.questions)
  • Re: CRT time function depends on timezone?
    ... > It sounds like a good reason to make it work incorrectly on Windows ... It says upfront that "The GetSystemTime ... The system time is ... supported Win32 platforms _will_ return UTC: if you find one that doesn't, ...
    (microsoft.public.vc.language)