LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   change system-wide date format (https://www.linuxquestions.org/questions/linux-newbie-8/change-system-wide-date-format-4175693795/)

bg368 04-16-2021 09:40 AM

change system-wide date format
 
The 'date' command on my system is formatted to show the results as: Fri 16 Apr 20 21 10:26:01 AM EDT.
Since the date command is so versatile I wonder if it is possible to change the way dates and times show up in various commands such as 'ls' and the like.
I assume it would be to change the LC_TIME parameter system wide, but I cannot find where it is originally set. Any help is very much appreciated

rtmistler 04-16-2021 09:44 AM

I don't know the answer either, but as opposed to any assumption surrounding LC_TIME, perhaps instead give the source for 'ls' or another command concerned a quick look and determine how it processes the date/time for the output it generates. Because if it is a property, then great.

computersavvy 04-16-2021 10:07 AM

"man date" gives lots of formatting information, and if you want the display to be formatted different than the default it should be easy to design a format that satisfies you then make it an alias for your user so it always displays the way you wish. The alias could be put into ~/.bashrc if you are using bash.
My default display, using fedora is
"Fri Apr 16 10:01:51 AM CDT 2021"

Using an alias means you would not have to mess with the default config.

shruggy 04-16-2021 10:19 AM

1) /etc/default/locale. Changed by update-locale.

2) /etc/locale.conf. Changed by localectl.

3) localehelper from the eponymous package. Used like this:
Code:

localehelper LANG=C -- ls -l
4) If the locale in question is already configured (e.g. sudo dpkg-reconfigure locales) then this does much the same:
Code:

LC_ALL=C ls -l

bg368 04-16-2021 10:38 AM

Thanks, Shruggy. That oughta do it.

computersavvy 04-16-2021 10:47 AM

This is strange.
on my system I see that /etc/locales.conf gives the following for the default and en_US locales.
Code:

[default]
        date format = %b %e %Y %I:%M:%S:%z%p

[en_US]
        date format = %b %e %Y %I:%M:%S:%z%p
        language = us_english
        charset = iso_1

Both those are identical, and my locale is en_US but the date command gives
"Fri Apr 16 10:01:51 AM CDT 2021"
So the config for the date displayed does not match the formatting given in that config file.

shruggy 04-16-2021 12:14 PM

@computersavvy. locales.conf is different from locale.conf. I meant the latter.

computersavvy 04-16-2021 01:49 PM

On my system I have both, and the locale.conf only lists the language for the locale (LANG="en_US.UTF-8")

Obviously a difference in the way different distros are configured.


All times are GMT -5. The time now is 05:28 PM.