c++在linux上打印毫秒级时间戳,从而实现打日志功能

#include
#include
int main(void)
{
while(true)
{
std::chrono::system_clock::time_point now = std::chrono::system_clock::now();
auto tt = std::chrono::system_clock::to_time_t(now);
struct tm* ptm = localtime(&tt);
char current_time[128] = { 0 };
char current_date[20] = { 0 };
char date_path[100] = { 0 };

	std::chrono::milliseconds ms = std::chrono::duration_cast<std::chrono::milliseconds>(now.time_since_epoch()) % 1000;
	sprintf(current_date, "%d%02d%02d", (int)ptm->tm_year + 1900, (int)ptm->tm_mon + 1, (int)ptm->tm_mday);
	sprintf(current_time, "%s %02d:%02d:%02d.%d", current_date, ptm->tm_hour, ptm->tm_min, ptm->tm_sec, (int)ms.count());
	
	printf("输出:%s\n", current_time);
	::Sleep(10);
}
return 0;

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值