C ++ formatting date format

I have a vector date string in the format "dd-mmm-yyyy", for example, Today's date will be:

  std::string today("07-Sep-2010"); 

I would like to use the date class in boost, but to create a date object, the constructor for the date should be called like this:

 date test(2010,Sep,07);

Is there a simple / elegant way to transfer dates in the "dd-mmm-yyyy" format? My first thought was to use substr and then toss it? But I read that there is also the possibility of using "date phases"?

Thank!

+3
source share
2 answers
include "boost/date_time/gregorian/parsers.hpp"
date test = boost::gregorian::from_us_string("07-Sep-2010")
+3
source

Boost, :

http://www.boost.org/doc/libs/1_44_0/doc/html/date_time/date_time_io.html#date_time.io_objects

date_type parse_date (...) :    string_type    string_type   special_values_parser .

string inp("2005-Apr-15");
string format("%Y-%b-%d");
date d;
d = parser.parse_date(inp, 
                      format,
                      svp);
// d == 2005-Apr-15

inp .

+2

Source: https://habr.com/ru/post/1763607/


All Articles