C ++中有标准的日期/时间类吗? [英] Is there a standard date/time class in C++?
问题描述
time_t tm();
ostringstream sout;
sout<<< tm <结束
在这种情况下,我将当前的日期/时间写成一个没有任何格式的数字。我可以使用
c-运行时函数 strftime
先格式化tm,但是如果stl有一个可以实例化的时间类,那似乎不是必需的from time_t value
不是STL的一部分,而是众所周知的库是boost。
我会去使用 boost :: date
的方法。以下是一些示例: http:// www.boost.org/doc/libs/1_55_0/doc/html/date_time/date_time_io.html#date_time.io_tutorial 。
如果没有尝试我鼓励你这样做,因为它可以节省你从很多讨厌的问题,因为它掩盖了大多数操作系统依赖的东西,如线程例如。 boost
中的许多内容只是标题(模板库)。但是datetime需要一个lib或dll。
Does C++ stl have a standard time class? Or do I have to convert to c-string before writing to a stream. Example, I want to output the current date/time to a string stream:
time_t tm(); ostringstream sout; sout << tm << ends;
In this case I get the current date/time written out as a number without any formatting. I can use
c- runtime function strftime
to format tm first, but that seems like it should not be necessary if the stl has a time class that can be instantiated from time_t value
Not part of STL but well known library is boost.
I would go the way of using boost::date
. Here are some examples: http://www.boost.org/doc/libs/1_55_0/doc/html/date_time/date_time_io.html#date_time.io_tutorial.
If you did not try out boost yet I encourage you to do so as it saves you from a lot of nasty issues, as it masks most OS dependent things like threading for example. Many things in boost
are header only (template libraries). However datetime requires a lib or dll.
这篇关于C ++中有标准的日期/时间类吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!