首页 > 解决方案 > 格式化时间 c++ dd/mm/yyyy hh:ss

问题描述

我正在尝试获取日期和时间(现在),这是我到目前为止所得到的:

16/1/2020 13:24

如何获得 dd/mm 以及如何设置非 UTC 时间?时间应该是下午 12 点 24 分

time_t rawtime
struct tm ltm;
time(&rawtime)

localtime_s(&ltm, &rawtime)

std:stringstream date;
date << ltm.tm_mday
<< "/"
<< 1+ ltm.tm_mon
<<"/"
<<1900 + ltm.tm_year
<< " "
<< ":"
<< 1 + ltm.tm_min;
std::cout << date.str() << "\n";

标签: c++time-t

解决方案


time_t rawtime
struct tm ltm;
time(&rawtime)

localtime_s(&ltm, &rawtime)
std::ostringstream ss;
ss << std::put_time(&ltm, "%d/%m/%Y %H:%M");
std::cout << ss.str() << endl;

推荐阅读