Assuming the locale is set up properly, you can use:
https://en.cppreference.com/w/cpp/locale/time_get/date_order
Returns a value of type std::time_base::dateorder
, which describes the default date format used by this locale (expected by get_date()
and produced by std::strftime()
with format specifier '%x'
).
std::time_base::dateorder d = std::use_facet<std::time_get<char>>(
std::locale()
).date_order();
switch (d)
{
case std::time_base::no_order: std::cout << "no_order\n"; break;
case std::time_base::dmy: std::cout << "day, month, year\n"; break;
case std::time_base::mdy: std::cout << "month, day, year\n"; break;
case std::time_base::ymd: std::cout << "year, month, day\n"; break;
case std::time_base::ydm: std::cout << "year, day, month\n"; break;
}
NOTE: This function is optional, it may return no_order in every case.
Unfortunately I can only get it to print no_order
. I'm not sure if this is a problem with the compiler, locale, or system I'm running it on. The example on cppreference gives me no_order
for everything so my guess is the compiler (I've tried gcc and clang) hasn't implemented it.
There may be system-specific calls that will give you what you want.