boost::date_time中将英文月份输出为汉字

45 篇文章 181 订阅 ¥9.90 ¥99.00
本文介绍如何使用Boost::date_time库将日期时间的英文月份转换为汉字进行格式化输出,例如将'Mar'转换为'3月',以实现如'2020-03-17 22:41:08 899412'这样的日期时间格式。
摘要由CSDN通过智能技术生成

1、boost的date_time库中的月份默认都是用英文来表示的,如Mar是3月。。。,有时我们想输出如下格式的时间到文件中:2020-03-17 22:41:08 899412,下面给出格式化输出方法:

#include <iostream> 
#include <boost/date_time/posix_time/posix_time.hpp>

std::string ptime_to_string(boost::posix_time::ptime now)
{
	std::stringstream ss;
	static std::locale loc(ss.getloc(), new boost::posix_time::time_facet("%Y-%m-%d %H:%M:%S %f"));
	ss.imbue(loc);
	ss << now;
	return ss.str();
}


int main()
{
	boost::posix_time::ptime pNow = boost::posix_time::microsec_clock::local_time();
	std::string strNow = ptime_to_string(pNow);
	std::cout << strNow << std::endl;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小米的修行之路

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值