unsigned long long 到 std::chrono::time_point 并返回
我对某件事很困惑。给定:
std::time_t tt = std::time(0);
std::chrono::system_clock::time_point tp{seconds{tt} + millseconds{298}};
std::cout << tp.time_since_epoch().count();
打印类似:16466745672980000
(例如)
如何将该数字重新水合回 time_point
对象?我发现自己做了一些奇怪的事情(我不想在这里展示),我想问一下补液的正确方法是什么。
I am very confused about something. Given:
std::time_t tt = std::time(0);
std::chrono::system_clock::time_point tp{seconds{tt} + millseconds{298}};
std::cout << tp.time_since_epoch().count();
prints something like: 16466745672980000
(for example)
How do I rehydrate that number back into a time_point
object? I find myself doing kooky things (that I'd rather not show here) and I'd like to ask what the correct way to do the rehydration is.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
system_clock::duration
的单位因平台而异。在您的平台上,我猜它是 1/10 一微秒。出于序列化目的,您可以记录这是 1/10 微秒的计数。这可以通过以下方式可移植地读回:
如果本机
system_clock::time_point
的精度与D
一样好或更精细,您可以隐式转换为它:否则您可以选择通过选择向上舍入、向下舍入、到最接近的舍入或向零舍入来截断它。例如:
The units of
system_clock::duration
vary from platform to platform. On your platform I'm guessing it is 1/10 of a microsecond.For serialization purposes you could document that this is a count of 1/10 microseconds. This could be portably read back in with:
If the native
system_clock::time_point
has precision as fine asD
or finer, you can implicitly convert to it:Otherwise you can opt to truncate to it with a choice of rounding up, down, to nearest, or towards zero. For example: