I am using Ubuntu 18.04.4 LTS with GNOME DE and I want to change my systemwide date and time format to ISO 8601 format, specifically YYYY-MM-DD for dates and hh:mm:ss for times.
How can I do this?
1 Answer
For a point of reference you may want to run these commands first, maybe keep the output in a terminal off to the side:
localectl status
locale
locale -ck d_t_fmt
locale -ck d_fmt
locale -ck t_fmtThen in another terminal cd /usr/share/i18n/locales
Locate whichever locale you are using in the directory...
For me that was en_US.
Copy that locale definition file to a custom_name you wish to use.
sudo cp en_US my_en_US
With your favorite editor, edit your custom locale definition file with the desired date formats.
The OP wanted systemwide format for his date/time... well there is more than one date/time formatting on the system, so you'll be doing a lot of formatting here if you want everything covered. ie. Date, Date time, time, time AM/PM format, date for the date command...(as you will see in the definition file)
I am only going to illustrate one of the above here.... The date format for the date command.
sudo vi my_en_US
Go to the line that says "date_fmt" Edit the formatting to the desired format.
date_fmt "%Y-%m-%d %H:%M:%S"
note: I have read some instructions that say you enter this formatting with Unicode values instead ex) "<u0025><u0059> ,etc,etc".... But since they were not this way in this version of ubuntu, I am assuming you can just use percent encoding... If your file has the Unicode format, you can take the date/time string you desire, in percent format, and run it through hexdump to get the Unicode equivalents... echo -n "%Y-%m-%d %H:%M:%S" | hexdump or use this site
Save your file and exit...
Complie your locale definition file and generate your new localesudo localedef -f UTF-8 -i my_en_US MY_en.UTF-8
There are instructions out there that say add an environment variable to /etc/environment or /bashrc etc...
but all I did was sudo localectl set-locale LC_TIME=MY_en.UTF-8
It took immediately for me when I ran the date command. But you may have to log out or reboot, I am not sure there. The services to restart have changed over time (according to the rest of the internet), so hard to decipher.
You can run the commands from the beginning of the post again for comparison/troubleshooting.