Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <boost/date_time/posix_time/posix_time.hpp>
- #include <iostream>
- int main( int argc, char** argv )
- {
- auto now = boost::posix_time::second_clock::local_time();
- std::stringstream outStr;
- {
- boost::posix_time::time_facet* facet = new boost::posix_time::time_facet();
- facet->format("%Y-%m-%dT%H:%M:%S.%f");
- outStr.imbue(std::locale(std::locale::classic(), facet));
- outStr << now;
- }
- std::cout << outStr.str() << std::endl;
- {
- static const std::string format = "%Y-%m-%dT%H:%M:%S.%f";
- const std::locale loc = std::locale(std::locale::classic(), new boost::posix_time::time_input_facet(format));
- std::istringstream is(outStr.str());
- is.imbue(loc);
- boost::posix_time::ptime converted;
- is >> converted;
- std::cout << converted << std::endl;
- }
- {
- static const std::string format = "%Y-%m-%dT%H:%M:%S%f";
- const std::locale loc = std::locale(std::locale::classic(), new boost::posix_time::time_input_facet(format));
- std::istringstream is(outStr.str());
- is.imbue(loc);
- boost::posix_time::ptime converted;
- is >> converted;
- std::cout << converted << std::endl;
- }
- return 0;
- }
- 2019-04-30T12:23:29.000000
- not-a-date-time
- 2019-Apr-30 12:23:29
- 2019-04-30T12:23:29.000000
- 2019-Apr-30 12:23:29
- not-a-date-time
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement