Skip to content

[Linux] How to Change the Display Language of `date` Command

Last Updated on 2022-12-08 by Clay

Today when I used date command to check the current date and time, I got the following Chinese display result:

西元2022年09月27日 (週二) 19時41分14秒 CST

But my environment should be English! Is it because I live in Taipei?

As an engineer who hopes to work carefully, I began researching how to change the language for displaying dates.


Show the current system date-time format

First at all, We can find the current date-time format with LC_TIME environment variable.

There are many types of LC_XXX format, such as LC_CTYPE is set for character format, and LC_NUMERIC is set for number displaying...

Among them, LC_ALL can set all formats at once to a specific region, but that is too rough. I prefer to set the configuration I want more accurately.

We can use the following command:

echo $LC_TIME


Output:

zh_TW.utf8


And we can see the current configure of time format.

Of course, all are determined by environment variables. However, If you try to configure the environment variables in terminal, the settings will be effective until you exit your terminal. When you reopen the terminal again, the date and time will still maintain the original system default value.

So you can write down the settings into ~/.bashrc file, even change the system default settings. (But in co-work server, I do not recommend doing that)



Display the system format you can use

locale -a


Output:

C
C.utf8
POSIX
en_AG
en_AG.utf8
en_AU.utf8
en_BW.utf8
en_CA.utf8
en_DK.utf8
en_GB.utf8
en_HK.utf8
en_IE.utf8
en_IL
en_IL.utf8
en_IN
en_IN.utf8
en_NG
en_NG.utf8
en_NZ.utf8
en_PH.utf8
en_SG.utf8
en_US.utf8
en_ZA.utf8
en_ZM
en_ZM.utf8
en_ZW.utf8
lzh_TW
lzh_TW.utf8
zh_HK.utf8
zh_TW.utf8




Change the date-time format

You can edit /etc/default/locale file with sudo.

sudo vim /etc/default/locale


Output:

LANG=C.UTF-8
LANGUAGE=
LC_CTYPE=C.UTF-8
LC_NUMERIC=lzh_TW
LC_TIME=zh_TW.utf8
LC_COLLATE="C.UTF-8"
LC_MONETARY=lzh_TW
LC_MESSAGES="C.UTF-8"
LC_PAPER=lzh_TW
LC_NAME=lzh_TW
LC_ADDRESS=lzh_TW
LC_TELEPHONE=lzh_TW
LC_MEASUREMENT=lzh_TW
LC_IDENTIFICATION=lzh_TW
LC_ALL=


As mentioned above, you can directly modify LC_TIME to en_US.utf8.

Or, you can also use localectl to change the setting. This way will be effect the next time you open the terminal.

sudo localectl set-locale LC_TIME=en_US.utf8


These settings will take effect permanently. After modifying them, the date and time format that I displaying is roughly as follows:

date


Output:

Tue Sep 27 08:04:29 PM CST 2022


It perfectly meets my requirements for the system language.


References


Read More

Tags:

Leave a Reply