简体   繁体   English

c ++数据类型和函数可与“ days”一起使用

[英]c++ data type and functions to work with “days”

I'm looking for c++ type and functions to work with "days". 我正在寻找c + +类型和函数以使用“天”。

In particular I need to: 特别是我需要:

  • convert strings like "20140224" to datatype and vice versa (of course i can parse strings myself to int if necessary - 2014, 02, 24) 将类似“ 20140224”的字符串转换为数据类型,反之亦然(当然,如有必要,我可以将字符串自己解析为int-2014、02、24)
  • "iterate", for example from "20140101" to "20140224" “迭代”,例如从“ 20140101”到“ 20140224”

I don't need: 我不需要:

  • time of the day. 一天中的时间。 current day is "smallest" pieace i'm working with 今天是我正在与“最小”的和平

I can use c++11, what can you recommend? 我可以使用c ++ 11,您有什么建议?

C++ has always stayed away from implementing a standard date library. C ++始终远离实现标准日期库。

They are, in general, very hard to implement and standardise. 通常,它们很难实施和标准化。 ISO8601 provides some guidance but issues such as leap-seconds, and unusual calendars (eg Ethiopia) will always be tricky areas. ISO8601提供了一些指导,但是诸如leap秒和异常日历(例如埃塞俄比亚)之类的问题始终是棘手的领域。

Boost (www.boost.org) certainly makes inroads. Boost(www.boost.org)当然取得了进展。 Refer to their date-time library. 请参阅其日期时间库。 Unfortunately it's quite heavyweight and the build process takes a while to get used to, but worth attempting. 不幸的是,它非常笨重,构建过程需要一段时间才能习惯,但是值得尝试。

(As an aside, Java have attempted it but the date time library in Java is widely considered to be broken). (顺便说一句,Java曾尝试过,但人们普遍认为Java中的日期时间库已损坏)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM