Reputation: 171
I need to create a timestamp with boost in the format: YYYYmmDDhhMMssFFFF (with F = Milliseconds). I use
facet->format("%Y%m%d%H%M%S%F");
but the output includes always a dot between seconds and milliseconds. This is the output: "20150202140830.779716"
Is there a better way to achieve my format than to replace the dot and cut the last two digits by hand?
Upvotes: 1
Views: 2171
Reputation: 393709
In case you're interested, I implemented a custom facet the other day here: Format a posix time with just 3 digits in fractional seconds
You could use the same approach here:
#include "time_facet.hpp"
#include <boost/date_time/posix_time/posix_time.hpp>
int main()
{
using namespace boost::posix_time;
ptime const date_time = microsec_clock::local_time();
std::cout << date_time << std::endl;
auto facet = new time_facet("%Y-%b-%d %H:%M:%S%4 %z");
std::cout.imbue(std::locale(std::cout.getloc(), facet));
std::cout << date_time << std::endl;
}
Prints:
2015-Feb-02 22:01:00.926982
2015-Feb-02 22:01:009269
Upvotes: 1