How to implement universal time, local time and home time

王朝vc·作者佚名  2006-01-09
宽屏版  字体: |||超大  

Local time

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;

--------------------------------------------------------------------------------

Home time

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

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
© 2005- 王朝网络 版权所有