Galvotas Galvotas - 5 months ago 8
Linux Question

How to get local (regional) date format in linux?

is it possible (if so, how?) to get local (regional) date format? Ideally in cross-platform way, otherwise at least Linux for start would be enough.

What am I talking about: For example this line when executed in terminal returns date (and time) formatted in local (regional) manner:

date +"%c"


What I would like to have instead of the numbers is the form in which this is displayed, for example if I set my regional setting to Lithuanian ones I get:

2016 m. bir┼żelio 27 d. 19:06:11


So I would like to get this instead of the above:

YYYY MM DD


If I set regional settings to US ones:

Mon 27 Jun 2016 07:09:24 PM EEST


In this case instead of the above I would like to get:

DD MM YYYY


Meaning - not the actual numbers, but how local(regional) date is formatted.

I later want to use this information for input/output operations facing user

Answer

While Joachims hint is correct, here a solution for your original question. Just enter in bash:

locale -k LC_TIME | grep ^d_fmt | cut -d= -f2

If you need the time format instead of the date format, use t_fmt instead of d_fmt, and for the combined date/time format use d_t_fmt