All Forums
 Microsoft Windows CE
 General CE
 Configuring Time Zones in Windows CE
 Forum Locked  Topic Locked
 Send Topic to a Friend
 Printer Friendly
Author Topic  

jnosek

3 Posts

Posted - 19 Jan 2007 :  12:08:06  Show Profile  Email Poster

Configuring Time Zones in WinCE

There are three ways to set and persist the time zone settings on an ADS WinCE system. Each has its own benefits and drawbacks, so the best choice depends on the requirements of your application. It is important to understand that WinCE keeps track of two clocks, Local Time, and System Time. Local Time is the current time at your time zone location. System Time is always set to Greenwich Mean Time. These clocks are then used to calculate the File Time for files and to keep the file system update and coordinated.

Starting in March 2007, the United States will be switching to Extended Day Light Savings Time. This will require an update to the WinCE Time Zone Registry Keys to reflect the change in the start and end dates of Day Light Savings Time. This article on the MSDN explains how Day Light Savings Time works in WinCE and the changes to the registry that you may have to make to your system to support the new changes.

  • Through the Date/Time Control Panel Applet

    The Date and Time Settings Control Panel Applet is the easiest and most preferred way of setting and changing the time zone, date, and time on your system. The panel will do all the work for you by automatically adjusting the current time based on a time zone change, change in current time or date, or change for daylight savings. It is also very similar to the Date/Time Panel found on Windows Desktop PCs, so most users will be familiar with it.

    From the WinCE Desktop

    1. Double Click on the displayed time in the lower right hand corner of the task bar, or click on Start->Control Panel and double click the "Date and Time" Icon.

    2. Select the desired time zone from the drop down list, click Apply, and the time will be adjusted according to the time zone change. Then change the current time if necessary.

    3. Click on Start->Run and run the command "regflushkeys.exe". This is necessary to store the new time zone settings into the Hive Registry. If you do not do this step, the board will boot next time with the correct time, but the incorrect time zone.

    If you choose not to run explorer.exe upon system start up, the end user will not have access to the WinCE Desktop. The Date/Time Control Panel Applet can still be called though to change the system time settings. Follow the directions and sample code below.

    Called From Application Code

    1. Call CreateProcess() using the following code as an example. (also see Topic 70)

    2. Wait for the user to make the necessary changes and close the panel.

    3. Open the registry keys [HKEY_LOCAL_MACHINE\Time Zone] and [HKEY_LOCAL_MACHINE\Time], flush them to the Hive registry, and close them. This will make sure the changes made will be saved in the registry.

    Example Code:
    PROCESS_INFORMATION pi;
    HKEY hKey;

    // Create Process
    if(!CreateProcess(TEXT("ctlpnl.exe"), TEXT("cplmain.cpl,13"), NULL, NULL, FALSE, 0, NULL, NULL, NULL, &pi))
    {
    RETAILMSG(1, (TEXT("Error: Unable to create process, Error: %d\\\r\\\n"), GetLastError()));
    return -1;
    }

    // Wait for user to close panel
    WaitForSingleObject(pi.hProcess, INFINITE);

    // Flush Registry Keys
    RegOpenKeyEx(HKEY_LOCAL_MACHINE, TEXT("\\Time"), 0, NULL, &hKey);
    RegFlushKey(hKey);
    RegCloseKey(hKey);

    RegOpenKeyEx(HKEY_LOCAL_MACHINE, TEXT("\\Time Zones"), 0, NULL, &hKey);
    RegFlushKey(hKey);
    RegCloseKey(hKey);

  • Through Application Software - Timezone.exe

    The time zone and time can also be set through your application directly. The following sample code from Timezone.exe will change the time zone to Eastern Standard Time and set the time to 12:00pm. This code reads the Time Zone Information (TZI) from the registry and will set the time zone to this new information, and then flush the proper registry keys to make this change persistent.

    It is important to note that by changing the time zone this way, with out setting the time, will not change the Local Time, but will adjust the System Time.

    Example:
    1. Current Time:
      Local Time = 12:00 EST
      System Time = 17:00 GMT

    2. Changing the time zone of the system to PST will result in:
      Local Time = 12:00 PST
      System Time = 20:00 GMT

    Key APIs Used

    GetLocalTime
    SetLocalTime
    GetSystemTime
    GetTimeZoneInformation
    SetTimeZoneInformation
    RegOpenKeyEx
    RegQueryValueEx
    RegFlushKey
    RegCloseKey
    TZREG
    If it is not 12:00pm at the time zone you have set the system to, you will now have to set the clock to the correct current time to get both the Local Time and System Time to the correct time. One option is to retrieve the current time from a time zone server. You can also try to adjust the Local Time by reading the previous TZI and the new TZI and calculate the hour difference. This can become tedious for the special exceptions, like time zones with half hour differences and day light savings time. The Date/Time Control Panel Applet already does this work for you and can handle asking the user to set the current time, which is why it is preferred method.

    Source Download
    Rev 1 - (Jan 19, 2007) (9k zip)


  • Through ADSLoad.reg

    The time zone can also be set through ADSLoad.reg, but this will lock the system into the configured time zone since the ADSLoad.reg is parsed and added to the system registry upon every boot. Changing the time zone through other means on a system set up this way can result in a system having the correct Local Time for a specified time zone, but internally WinCE thinks it is in a different time zone, therefore an incorrect System Time.

    Example:
    1. Board set to EST through ADSLoad.reg:
      Local Time = 12:00 EST
      System Time = 17:00 GMT

    2. System changed to 1:00pm PST through Date/Time Control Panel Applet:
      Local Time = 13:00 PST
      System Time = 21:00 GMT

    3. Board is immediately rebooted:
      Local Time = 13:00 EST
      System Time = 18:00 GMT

    Though the board correctly displays 1:00pm, the System Time is 3 hours off from GMT. This could have even stranger effects if the system is hooked up to remote file servers, since the System Time is used to compute File Time. Files on the remote system could be view as newer or older depending on circumstances.

    If you wish to use this option, follow these steps:

    1. On one system, set the time zone using the Date/Time Control Panel Applet to the zone you would like to use on other systems.

    2. Using regedit.exe, export the [HKEY_LOCAL_MACHINE\Time\TimeZoneInformation] Key. This should contain the binary data for the current Time Zone Information the system is configured for.

    3. Copy this key into an ADSLoad.reg file you wish to load on other systems. Make sure to remove the "\\\\" characters and condense the hex string to one line. The ADSLoad.reg parser does not parse "\\\\" characters. When the ADSLoad.reg is parsed, it will add the Time Zone Information into the registry to configure the system to the time zone you had set on the previous board.

    If you wish to remove this hard coded time zone, you must reload the ADSLoad.reg on the system with one that does not include the [HKEY_LOCAL_MACHINE\Time\TimeZoneInformation] key, and set the new time zone by another method and flush it to the registry.

Edited by - jnosek on 19 Jan 2007 12:22:17
  Topic  
 Forum Locked  Topic Locked
 Send Topic to a Friend
 Printer Friendly
Jump To:
Eurotech Support Forums © Eurotech Inc. Go To Top Of Page
This page was generated in 0.03 seconds. Snitz Forums 2000