unix timestamp to boost::posix_time::ptime

cube picture cube · Jul 22, 2009 · Viewed 17.8k times · Source

I need to convert double with number of seconds since the epoch to ptime. I'm prety sure there must be an easy way to do this, but I couldn't find anything. Thanks.

Edit: The original timestamp is floating point. I can't change it and i don't want to lose the sub-second precision.

Answer

John Kugelman picture John Kugelman · Jul 22, 2009

Use the from_time_t() conversion function. A time_t is a UNIX timestamp, i.e. the number of seconds since the epoch.