Set clock to 24 hour format for all users
If you use the date
command on the command line, and get back something like Fri 22 Nov 2019 02:47:51 PM EST
, then it means your locale settings are currently set to a locale that specifies a 12-hour time format.
Type locale
to view the current locale settings. Basically, all the locale settings are just environment variables, but there are some dependencies between them.
The logic of the locale settings is as follows:
First, the
LANG
variable will define the default locale for all theLC_*
locale categories, unless there is a more specific setting for a particular category.Each locale category has a name, like
LC_CTYPE
for the character set being used,LC_COLLATE
for sorting order, andLC_TIME
for the representation of date and time. If an environment variable corresponding to the name of the locale category exists, it will override the default set byLANG
.Finally, there is an ultimate override
LC_ALL
. If it is set, it will override all the other locale settings. It is typically used in scripts or similar asexport LC_ALL=C
, to ensure that the output of any commands used by the script will be in the POSIX default US English format instead of any localized format that might make parsing the output more difficult. (Of course, parsing the output intended for humans in a script is a non-ideal choice in the first place - if a command has a "script-friendly output" option, you should use it instead!)
Historically, on RedHat/Fedora, the system default locale settings should be in /etc/sysconfig/i18n
file (i18n = internationali[s|z]ation, 18 characters between i and n). On modern versions, ther should be a localectl
command you can use to query and modify the locale and keyboard layout settings persistently. Note that environment variable settings can always be used to override system-wide locale defaults!
If you are using the default en_US.UTF-8
locale, then en_GB.UTF-8
would be the closest equivalent with 24-hour time representation. To set it, use:
localectl set-locale LC_TIME=en_GB.UTF-8
Then logout & log back in to have the change take effect in your session.
If you use some other locale, use localectl list-locales
to see the available locale definitions.
If you are unsure, you can test the output by specifying the desired locale as an environment variable for the date
command:
$ LC_TIME=en_GB.UTF-8 date
Sat 23 Nov 15:47:16 EET 2019
$ LC_TIME=en_US.UTF-8 date
Sat 23 Nov 2019 03:47:19 PM EET
Raul
Updated on September 18, 2022Comments
-
Raul almost 2 years
On Fedora 30, I'm currently displaying the date in 24 hour format in the desktop environment. I'm syncing time via chronyd. But on the CLI, the time is displaying as
Fri 22 Nov 2019 02:47:51 PM EST
for all users.I want to set the time format to use the 24 hour clock.
timedatectl
setting and re-logging as the user does not make any difference. -
rodvlopes about 4 yearsFor a more "Computerized" locale, I prefer:
localectl set-locale C.UTF-8
. It's still english but more standardized for computers. The time format is 24h.