Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert double to time_t

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

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

like image 788
Jonathan Mee Avatar asked Jun 23 '15 10:06

Jonathan Mee


1 Answers

The type of std::time_t is unspecified.

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.

like image 176
masoud Avatar answered Sep 22 '22 12:09

masoud