If you want to use the local date format you can try std::get_time
(available since C++11)
When used in an expression in >> get_time(tmb, fmt), parses the character input as a date/time value according to format string fmt according to the std::time_get facet of the locale currently imbued in the input stream in.
or the POSIX C function strptime
with "x"
as format.
| x | parses the locale's standard date representation | all |
-- cppreference.com
Both return calendar time struct tm
that you can convert it to timestamp using either localtime
or gmtime
if you want.
Note that you have to set the C and C++ locale of your application before, in order to be able to use your OS regional settings and not the classic C locale. See locale
and std::locale
. And it's good to set both so that they are in sync and not get bad surprises.
setlocale(LC_ALL, "");
std::locale::global(std::locale(setlocale(LC_ALL, NULL)));