Last active
January 4, 2019 18:18
-
-
Save andrewcrabb/76caaac2e6411a274d13e0d90703ce25 to your computer and use it in GitHub Desktop.
Boost datetime to formatted output modified from http://bit.ly/2VwaARa http://cpp.sh/6mp4m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "boost/date_time/posix_time/posix_time.hpp" | |
#include <iostream> | |
#include <sstream> | |
std::string FormatTime(boost::posix_time::ptime now) | |
{ | |
using namespace boost::posix_time; | |
static std::locale loc(std::wcout.getloc(), | |
new wtime_facet(L"%Y%m%d_%H%M%S")); | |
std::stringstream wss; | |
wss.imbue(loc); | |
wss << now; | |
return wss.str(); | |
} | |
int main() { | |
using namespace boost::posix_time; | |
ptime now = second_clock::universal_time(); | |
std::string ws(FormatTime(now)); | |
std::cout << ws << std::endl; | |
sleep(2); | |
now = second_clock::universal_time(); | |
ws = FormatTime(now); | |
std::cout << ws << std::endl; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment