Reputation: 4767
At the moment I am getting the date and time in the following way:
std::string isoString = boost::posix_time::to_iso_string(boost::posix_time::second_clock::universal_time());
std::string date = isoString.substr(0,8);
std::string time = isoString.substr(9,16);
Problem: The milliseconds are missing and I need this information. How can I obtain the time with milliseconds?
Upvotes: 1
Views: 3168
Reputation: 8038
Why not C++11?
long long timestamp()
{
return chrono::duration_cast<chrono::milliseconds>(chrono::system_clock::now().time_since_epoch()).count();
}
Upvotes: 1
Reputation: 7929
You can use boost::posix_time::microsec_clock
:
std::string isoString = boost::posix_time::to_iso_string(boost::posix_time::microsec_clock::universal_time());
std::string date = isoString.substr(0,8);
std::string time = isoString.substr(9,20);
Upvotes: 2