使用boost库进行时间戳表达
int _tmain(int argc, _TCHAR* argv[])
{
/*
boost::posix_time::ptime now = boost::posix_time::second_clock::local_time();
boost::posix_time::ptime utc = boost::posix_time::second_clock::universal_time();
boost::posix_time::time_duration tz_offset = (now - utc);
std::stringstream ss;
boost::local_time::local_time_facet* output_facet = new boost::local_time::local_time_facet();
ss.imbue(std::locale(std::locale::classic(), output_facet));
output_facet->format("%H:%M:%S");
ss.str("");
ss << tz_offset;
// std::stringstream ss;
boost::local_time::time_zone_ptr zone(new boost::local_time::posix_time_zone(ss.str().c_str()));
boost::local_time::local_date_time ldt = boost::local_time::local_microsec_clock::local_time(zone);
// boost::local_time::local_time_facet* output_facet = new boost::local_time::local_time_facet();
// ss.imbue(std::locale(std::locale::classic(), output_facet));
output_facet->format("%Y%m%d-%H:%M:%S.000");
ss.str("");
ss << ldt;
std::cout << ss.str() << std::endl; // "2004-02-29 12:34:56.000789-05:00"
std::cout << "Press return to exit" << std::endl;
std::string wait_for_line;
std::getline(std::cin, wait_for_line);
*/
// string strPosixTime = boost::posix_time::to_iso_string(boost::posix_time::second_clock::local_time());
// 这时候strPosixTime里存放时间的格式是YYYYMMDDTHHMMSS,日期和时间用大写字母T隔开了,这里是以秒为单元,也可以换成
string strPosixTime = boost::posix_time::to_iso_string(boost::posix_time::microsec_clock::local_time());
int pos = strPosixTime.find('T');
cout << strPosixTime << endl;
strPosixTime.replace(pos,1,std::string("-"));
strPosixTime.replace(pos + 3,0,std::string(":"));
strPosixTime.replace(pos + 6,0,std::string(":"));
string finalStr = strPosixTime.substr(0, 21);
cout<<strPosixTime<<endl;
cout << finalStr << endl;
return (0);
}
posted on 2020-03-31 14:00 havent_2018 阅读(1173) 评论(0) 收藏 举报
浙公网安备 33010602011771号