Using boost parse datetime string: With single digit hour format

I’ll leave it to you to sort out how you want dates without years to be interpreted. However, here’s a quick start using /just/ strptime. I used it in a larger codebase, and we needed some pretty versatile date recognition. Behold: the adaptive datetime parser: #pragma once #include <string> #include <chrono> #include <cstdint> #include <list> … Read more

How to parse date/time from string?

Although I don’t know how to format a single-digit month input in boost, I can do it after the two-digit edit: #include <iostream> #include <boost/date_time.hpp> namespace bt = boost::posix_time; const std::locale formats[] = { std::locale(std::locale::classic(),new bt::time_input_facet(“%Y-%m-%d %H:%M:%S”)), std::locale(std::locale::classic(),new bt::time_input_facet(“%Y/%m/%d %H:%M:%S”)), std::locale(std::locale::classic(),new bt::time_input_facet(“%d.%m.%Y %H:%M:%S”)), std::locale(std::locale::classic(),new bt::time_input_facet(“%Y-%m-%d”))}; const size_t formats_n = sizeof(formats)/sizeof(formats[0]); std::time_t pt_to_time_t(const bt::ptime& pt) { … Read more