News:

Download Pelles C here: http://www.smorgasbordet.com/pellesc/

Main Menu

_ftime problem

Started by Greg, December 21, 2004, 08:38:12 AM

Previous topic - Next topic

Pelle

Hello Garvan,

Quote from: "Garvan"Sorry for not making my report clearer. localtime is also wrong.
No problems.

I use the Windows API function GetTimeZoneInformation() to get the time zone bias - it's the best I can find, but I'm no expert in this area.

If I set it to "(GMT+07:00) Bangkok, Hanoi, ..." on my Windows XP, I get TIME_ZONE_ID_UNKNOWN, but if I set it to "(GMT+07:00) Krasnoyarsk" I get TIM_ZONE_ID_STANDARD, Bias = -420.

I have attached the a simple test program for GetTimeZoneInformation() - what does it return on your computer?

Pelle
/Pelle

Garvan

Hi:

This is what I get! Same result with VC++

GetTimeZoneInformation() returned TIME_ZONE_ID_UNKNOWN
(Windows cannot determine the current time zone...)


Garvan

Greg

Garvan & Pelle,

That's what it should return under Windows NT/2000/XP. (GMT+07:00) Bangkok, Hanoi, Jakarta does not use Daylight Saving Time. So GetTimeZoneInformation() will return TIME_ZONE_ID_UNKNOWN, which is misleading.

See MSDN: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sysinfo/base/gettimezoneinformation.asp

It boils down to:
TIME_ZONE_ID_DAYLIGHT = Daylight Time
TIME_ZONE_ID_STANDARD or TIME_ZONE_ID_UNKNOWN = Standard Time
TIME_ZONE_ID_INVALID =  GetTimeZoneInformation() failed

Robert

For a related problem please see

SetLocalTime/GetLocalTime Not the Same if Adjusting for Daylight Savings Time

http://support.microsoft.com/kb/q234735/

Robert Wishlaw

Greg

Re: GetTimeZoneInformation

The meanings of the returned value changed with Windows NT. Some older code examples use the Windows 9x meanings.

Greg

An example of what I'm trying to say:

#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <stdio.h>

int main(void)
{
   TIME_ZONE_INFORMATION tzi;

   switch (GetTimeZoneInformation(&tzi))
   {
    case TIME_ZONE_ID_DAYLIGHT:
    /* Windows 9x/ME/NT/2000/XP - The current time zone is on Daylight Saving Time */
           printf("GetTimeZoneInformation() returned TIME_ZONE_ID_DAYLIGHT:\n");
           printf("Bias: %ld\n", tzi.Bias);
           printf("DaylightName: %ls\n", tzi.DaylightName); /* This is a Unicode string */
           printf("DaylightBias: %ld\n", tzi.DaylightBias);
           break;
           
       case TIME_ZONE_ID_STANDARD:
        /* Windows NT/2000/XP - the current time zone is on Standard Time */
        /* Windows 9x/ME - The current time zone does not use Daylight Saving Time or
          the current time zone is on Standard Time */
           printf("GetTimeZoneInformation() returned TIME_ZONE_ID_STANDARD:\n");
           printf("Bias: %ld\n", tzi.Bias);
           printf("StandardName: %ls\n", tzi.StandardName); /* This is a Unicode string */
           printf("StandardBias: %ld\n", tzi.StandardBias);
           break;
           
case TIME_ZONE_ID_UNKNOWN:
/* Windows NT/2000/XP - The current time zone does not use Daylight Saving Time */
        printf("GetTimeZoneInformation() returned TIME_ZONE_ID_UNKNOWN:\n");
           printf("Bias: %ld\n", tzi.Bias);
           printf("StandardName: %ls\n", tzi.StandardName); /* This is a Unicode string */
           printf("StandardBias: %ld\n", tzi.StandardBias);
           break;
     
    case TIME_ZONE_ID_INVALID:
           printf("Error calling GetTimeZoneInformation()\n");
           break;
                         
default:
           printf("GetTimeZoneInformation() returned unknown value\n");
           break;            
   }

   return 0;
}

Garvan

Hi:

Quote from: "Greg"
That's what it should return under Windows NT/2000/XP. (GMT+07:00) Bangkok, Hanoi, Jakarta does not use Daylight Saving Time. So GetTimeZoneInformation() will return TIME_ZONE_ID_UNKNOWN, which is misleading.

Thanks for this.

Garvan.

Pelle

Thank you very much for the information, Greg!

Pelle
/Pelle