Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c

date

linux

bash

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

like image 384
Galvotas Avatar asked Nov 28 '25 08:11

Galvotas


1 Answers

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

like image 169
Matthias Avatar answered Nov 29 '25 20:11

Matthias



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!