欢迎访问:常州市武进区嘉泽中心小学网站 !今天是:
栏目列表
您现在的位置是:首页>>教师>>计算机技术>>程序设计>>杂项>>文章内容
How to implement universal time, local time and home time
发布时间:2008-11-20   点击:   来源:本站原创   录入者:佚名
  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
附件:
    关闭窗口
    打印文档
    账号登录
    保持登录 忘记密码?
    账号与武进教师培训平台同步