c++ - 如何从 std::tm 转换为 Windows::Foundation::DateTime

标签 c++ windows-runtime

我正在尝试将 Windows 运行时组件中的 std::tm 转换为 Windows::Foundation::DateTime

Windows::Foundation::DateTime 中唯一的属性是 UniversalTime,它定义为:

A 64-bit signed integer represents a point in time as the number of 100-nanosecond interval prior to or after midnight on January 1, 1601 (according to Gregorian Calendar)

有没有办法在 std 中获取这个值?还是有一种标准的方法来进行转换?

最佳答案

您可以使用mktime 将您的时间转换为 unix, 然后添加魔数(Magic Number) 116444736000000000ULL:

    /* shift is difference between 1970-Jan-01 & 1601-Jan-01
    * in 100-nanosecond intervals */
    const uint64_t shift = 116444736000000000ULL; // (27111902 << 32) + 3577643008

来自 boost/date_time/filetime_functions.hpp

关于c++ - 如何从 std::tm 转换为 Windows::Foundation::DateTime,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33815816/

相关文章:

c++ - boost::assign 不适用于 += 的集合

c++ - 相对于类静态的原始全局变量的生命周期

c++ - 标准 C 函数声明语法 (WINAPI)

c++ - 来自嵌套列表的成员,如何调用外部数据

c++ - 围绕现有数组的 STL 非复制包装器?

uwp - 无法激活 IDL 中定义的投影类型

visual-studio-2010 - Visual Studio 2010 是否支持 Windows Metro 风格的应用程序?

javascript - 自定义站点 xxxx.com 使用需要桌面上 IE 消息的附加组件

sockets - 在 Metro 中处理套接字创建/销毁时的泄漏

windows-8 - 有没有办法在 Windows 8 metro 应用程序中获得推送滚动功能?