简体   繁体   中英

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

I'm looking for c++ type and functions to work with "days".

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)
  • "iterate", for example from "20140101" to "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++ has always stayed away from implementing a standard date library.

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.

Boost (www.boost.org) certainly makes inroads. 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).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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