Converting millisecond UTC to Human Readable Date_Time

こ雲淡風輕ζ 提交于 2019-12-01 22:57:58

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)

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.
  );
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!