将double转换为time_t [英] Convert double to time_t

查看:1038
本文介绍了将double转换为time_t的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 double 包含秒。我想将它转换为 time_t

I have a double containing seconds. I would like to convert this into a time_t.

我找不到一个标准函数来实现这一点。我必须手动填写 time_t 吗?

I can't find a standard function which accomplishes this. Do I have to fill out the time_t by hand?

推荐答案

std :: time_t 的类型未指定。

The type of std::time_t is unspecified.


虽然没有定义,但这几乎总是一个整数值,保存
从00开始计算的秒数(不包括闰秒) :00,Jan 1
1970 UTC,对应于POSIX时间。

Although not defined, this is almost always an integral value holding the number of seconds (not counting leap seconds) since 00:00, Jan 1 1970 UTC, corresponding to POSIX time.

精细。还要小心可移植性(因为它的类型没有在标准中指定),并考虑的值不能适合,而从双投入到积分。

So, just a safe casting between them could be fine. Also be carefull about portability (because it's type is not specified in the standard) and consider about the values than can not fit while casting from double to integrals.

这篇关于将double转换为time_t的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆