std :: put_time格式 [英] std::put_time formats

查看:866
本文介绍了std :: put_time格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想了解如何使用std :: put_time,以及如何以YYYY / MM / DD HH:MM:SS格式获取日期戳。现在我写这样的东西:

  std :: chrono :: time_point< std :: chrono :: system_clock> now = std :: chrono :: system_clock :: now(); 
std :: time_t now_c = std :: chrono :: system_clock :: to_time_t(now - std :: chrono :: hours(24));
std :: cout<< std :: put_time(std :: localtime(& now_c),%F%T)< '\\\
';

并输出为2011-10-25 12:00:08,如何获取日期正在提及的1小时前 stackoverflow.com/a/12346532/777186\">在这里,cppreference有很好的文档: http://en.cppreference.com/w/cpp/io/manip/put_time



具体来说,您可以使用以下方式获取您所述的格式格式字符串:

  std :: cout< std :: put_time(std :: localtime(& now_c),%Y /%m /%d%T)


I want understand how to work std::put_time, and how can I get date stamp in "YYYY/MM/DD HH:MM:SS" format. Now I write somthing like this:

std::chrono::time_point<std::chrono::system_clock> now = std::chrono::system_clock::now();
        std::time_t now_c = std::chrono::system_clock::to_time_t(now - std::chrono::hours(24));
        std::cout  << std::put_time(std::localtime(&now_c), "%F %T") << '\n';

and output is 2011-10-25 12:00:08, how can I get the date as 2011/10/25 12:00:08.

解决方案

As mentioned 1 hour ago here, cppreference has good documentation on this: http://en.cppreference.com/w/cpp/io/manip/put_time

Specifically, you can get the format you described using the following format string:

std::cout  << std::put_time(std::localtime(&now_c), "%Y/%m/%d %T")

这篇关于std :: put_time格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆