公正な警告:奇妙なタイムゾーン(+05:30?)があるように見えます。他のより:
Live On Coliru
#include <ctime>
#include <string>
std::string usingStrftime(const time_t rawtime)
{
struct tm * dt = localtime(&rawtime);
char buffer[30];
strftime(buffer, sizeof(buffer), "%Y-%m-%d %H:%M:%S", dt);
return std::string(buffer);
}
#include <boost/date_time/posix_time/posix_time.hpp>
#include <boost/date_time/posix_time/conversion.hpp>
#include <boost/date_time/posix_time/ptime.hpp>
boost::posix_time::ptime as_ptime(uintmax_t ns) {
return {{1970,1,1}, boost::posix_time::microseconds(ns/1000)};
}
#include <iostream>
int main() {
std::cout << usingStrftime(1507272767) << "\n";
auto timestamp = as_ptime(1507272767979279596ull);
std::cout << timestamp << "\n";
std::cout.imbue(std::locale(std::cout.getloc(), new boost::posix_time::time_facet("%A %b %d, %Y %I:%M:%S %p")));
std::cout << timestamp << "\n";
}
プリント
2017-10-06 06:52:47
2017-Oct-06 06:52:47.979279
Friday Oct 06, 2017 06:52:47 AM
'strftime'は溶液であってもよい(可能[重複](https://stackoverflow.com/questions/ 14436462/c-time-stamp-to-human-readable-datetime-function)?) – Vivick