【问题标题】:Getting UTC offset of system time zone on Mac (C++)在 Mac (C++) 上获取系统时区的 UTC 偏移量
【发布时间】:2013-02-21 14:57:41
【问题描述】:

我试图将系统时区表示为与 UTC 的偏移量(以分钟为单位)——类似于 Windows 函数 GetTimeZoneInformation(LPTIME_ZONE_INFORMATION)。 Corefoundation 或 Carbon 中有什么东西可以给我这些信息吗?

【问题讨论】:

    标签: c++ macos time macos-carbon core-foundation


    【解决方案1】:

    查看Date and Time Programming Guide for Core Foundation

    这是未经测试的,但是怎么样:

    CFTimeZoneRef tz = CFTimeZoneCopySystem();
    CFTimeInterval minsFromGMT = CFTimeZoneGetSecondsFromGMT(tz, CFAbsoluteTimeGetCurrent()) / 60.0;
    CFRelease(tz);
    

    【讨论】:

    • 谢谢!我不知道我为什么在疯狂的谷歌搜索中错过了那篇文章。
    • 太棒了。带着这么大的大脑,你一定脖子疼。?
    • @Duck 谢谢,但我可能从其他人那里得到了解决方案......
    猜你喜欢
    • 2014-01-09
    • 2016-05-07
    • 2013-10-15
    • 2020-10-21
    • 1970-01-01
    • 1970-01-01
    • 2016-01-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多