All Products
Search
Document Center

Alibaba Cloud Linux:What do I do if the date command displays the time in the 12-hour format in an Alibaba Cloud Linux 3 operating system?

Last Updated:Sep 19, 2024

The Alibaba Cloud Linux 3 operating system uses the 12-hour format. Other operating systems such as Anolis OS 8 and CentOS 8 use the 24-hour format. The time format inconsistency may cause inconvenience to users. This topic describes why Alibaba Cloud Linux 3 supports the 12-hour format and how to change the 12-hour format to the 24-hour format.

Problem description

In the output of the date command that is run in the Alibaba Cloud Linux 3 operating system, the time is displayed in the 12-hour format, and the time is suffixed with AM or PM.

Cause

In Alibaba Cloud Linux 3 operating systems, the patch (Glibc.git) included in the Glibc code automatically sets the time format in the en_US language to the 12-hour format.

Solutions

You can use one of the following methods to display the time in the 24-hour format:

Solution 1: Run a query command

Query the time.

LC_TIME=C.UTF-8 date

The time is in the 24-hour format, as shown in the following figure.

image

Scenario 2: Specify the 24-hour format

  1. Open the locale.conf file.

    sudo vim /etc/locale.conf
  2. Press the I key to enter Insert mode and add the following content to the file:

    LC_TIME=C.UTF-8
  3. Press the Esc key, enter :wq, and then press the Enter key to save and close the configuration file.

  4. Restart the system for the configuration to take effect.

    sudo reboot
  5. Query the time.

    date

    The time is in the 24-hour format, as shown in the following figure.

    image