c++ - 格式化时间 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(<m, &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";
解决方案
time_t rawtime
struct tm ltm;
time(&rawtime)
localtime_s(<m, &rawtime)
std::ostringstream ss;
ss << std::put_time(<m, "%d/%m/%Y %H:%M");
std::cout << ss.str() << endl;
推荐阅读
- reactjs - React Styled-components 未将样式应用于子元素
- json - 使用 jq 按键值过滤嵌套的 json
- css - 我怎样才能使这个字体大小顺利变小而没有跳跃?
- r - 如何将 R 的 read.table 与未定义数量的标题行一起使用?
- php - 毫秒格式 php
- javascript - http post请求的表单输入
- html - 我们可以在 HTML5 中使用大量的 div 标签吗
- java - 使用 Java 注释在方法中生成一些代码
- vim - UltiSnips 不会自动重新加载对片段文件的更改
- python - 带有时区错误的 Pandas date_range,可能的错误?