Converting between UTC and local time

Time zone ID

Each time zone is uniquely identified by its time zone ID which is a numeric reference or a name. The CTzId class encapsulates a time zone identifier. A time zone ID is created using the CTzId::NewL() factory method, for example:

       _LIT8( KAsiaHongKong,"Asia/Hong_Kong" ); //A valid time zone name
CTzId* zoneId = CTzId::NewL( KAsiaHongKong );
      

The time zone’s numeric ID or name can be retrieved using CTzId::TimeZoneNumericID() or CTzId::TimeZoneNameID() respectively.

operator==() and operator!=() can be used to check if the time zone ID matches or differs from another time zone ID.

Converting between UTC and local time

You can convert between times expressed in UTC and local time using either the CTzConverter or RTz class.

CTzConverter does the conversion on the client side by caching rules which it gets from the time zone server. This class should be used for conversion between UTC and local time for the system time zone, for performance reasons.

If the conversion involves foreign time zones, the RTz class can be used instead.

The following types of time conversion are possible:

Setting the local time

RTz::SetHomeTime() sets the local time in the system time zone:

       _LIT8( KMyTime, "20050105:103000.00" ); // Local time to set (5th January 2005 10:30 hrs).
TTime myTime( KMyTime ); //Create the time as a TTime object
TInt errCode = myTZoneServer.SetHomeTime( myTime );
      

The WriteDeviceData capability is needed to set the system time.

Automatic UTC offset

Whenever DST begins or ends, the UTC offset needs to be updated accordingly. This can be done automatically by calling RTz::SetAutoUpdateBehaviorL() . This function takes a value from the TTzAutoDSTUpdateModes enum. When set to TTzAutoDSTUpdateModes::ETZAutoDSTUpdateOn() , the UTC offset is automatically updated for changes to DST.