These code fragments demonstrate the various components which make up the time, including:
the universal time
the universal time offset
daylight saving.
In the following example code fragment, the universal time offset is added to the universal time, giving the local time. The universal time offset is determined by the locale's time zone. The offset is in seconds from universal time; this is positive for time zones east of universal time, and negative for time zones west of universal time.
TTime time;
TLocale locale;
// Get Universal time
time.UniversalTime();
// Get Universal time offset
TTimeIntervalSeconds universalTimeOffset(locale.UniversalTimeOffset());
// Add locale's universal time offset to universal time
// to get the local time
time+=universalTimeOffset;
Universal time offset alone does not determine a locale's home time. The daylight saving offset should also be taken into account.
Use TLocale::QueryHomeHasDaylightSavingOn()
to determine
whether daylight saving is in effect for the home locale.
...
// If home daylight saving in effect, add one hour offset.
if (locale.QueryHomeHasDaylightSavingOn())
{
TTimeIntervalHours daylightSaving(1);
time+=daylightSaving;
}
...
time
now contains the home time. This may be tested by
calling TTime::HomeTime()
, which should give the same
result.
TTime homeTime;
homeTime.HomeTime(); // homeTime==time