6

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.

1 Answer 1

19

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 the LC_* 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, and LC_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 by LANG.

  • 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 as export 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
7
  • 12
    For 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.
    – rodvlopes
    Jun 20, 2020 at 22:05
  • @rodvlopes Some distributions (e.g. older RHEL, I think?) do have the C locale, but not C.UTF-8... and the character set of the plain C locale might be constrained to essentially just US-ASCII.
    – telcoM
    Aug 9, 2022 at 16:40
  • How do I set locale for just this user? localectl set-locale LC_TIME=en_GB.UTF-8 ==== AUTHENTICATING FOR org.freedesktop.locale1.set-locale === Authentication is required to set the system locale. Jun 9 at 19:10
  • @AntonDuzenko Locale settings are essentially just environment variables. Put export LC_TIME=en_GB.UTF-8 to an appropriate login script and you're done. Desktop environments might even have a GUI tool for setting per-user locale settings.
    – telcoM
    Jun 9 at 19:53
  • Could you give an example? I have a server where LC_TIME="en_US.UTF-8" and it still prints in 24h format Jun 10 at 9:46

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .