#include <iostream>
#include <conio.h>
#include "string"
#include <boost/date_time/posix_time/posix_time.hpp>
#define BOOST_DATE_TIME_SOURCE
void Title_91()
{
std::string strTime = boost::posix_time::to_iso_string(\
boost::posix_time::second_clock::local_time());
// 这时候strTime里存放时间的格式是YYYYMMDDTHHMMSS,日期和时间用大写字母T隔开了
int pos = strTime.find('T');
strTime.replace(pos, 1, std::string("-"));
strTime.replace(pos + 3, 0, std::string(":"));
strTime.replace(pos + 6, 0, std::string(":"));
std::cout <<"当前时间为:"<< strTime.c_str() << std::endl;
}
int main()
{
Title_91();
return 0;
}
利用boost获取当前时间并且按照固定格式输出
于 2023-06-07 23:23:48 首次发布