更新时间:2022-12-18 10:29:40
time_t
时代,而不是毫秒。
如果你不关心毫秒,你应该能够这样做:
time_t
is usually seconds since "the epoch", rather than milliseconds.
If you dont care about milliseconds you should be able to do this:
std::time_t tt = static_cast<time_t>(ticksFromEpoch/1000)
如果您关心毫秒,您可以将它们添加回结束(对于像12:00:00.001 AM这样的时间来说很麻烦)
If you do care about milliseconds you can either add them back in at the end (which is tricky to get right for times like 12:00:00.001 AM )
或者你需要走另一条路线。您可能需要使用这样的:(未测试)
Or you'll need to go another route. You may need to use something like this: (untested)
boost::posix_time::ptime t2(
date(1970,Jan,1), //The epoch
boost::posix_time::seconds( ticksFromEpoch / 1000 ) + // Number of seconds
boost::posix_time::microseconds( ticksFromEpoch % 1000) // And the micros too.
);