|
Boost Users : |
Subject: Re: [Boost-users] [date_time] Creating a ptime from a double
From: Igor R (boost.lists_at_[hidden])
Date: 2009-11-03 04:26:41
> A lot of the constructors of ptime deals with getting the current system time or time structures. Â I have a double with the seconds and fractional microseconds from midnight January 1, 1970. Â What is the best way to create a ptime object from this double?
#include <boost/date_time/posix_time/posix_time.hpp>
#include <math.h>
namespace pt = boost::posix_time;
int main()
{
double d = 1000.1;
double sec;
double mksec = std::modf(d, &sec);
pt::ptime t = pt::from_time_t(static_cast<int>(sec)) +
pt::microseconds(static_cast<int>(mksec));
}
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net