Recently, I was twice asked about how to change the date format in Ubuntu. I have never bothered to tweak this part in my own setup. So, when asked, I assumed it would be easy to do at first. However, upon searching the Ubuntu desktop, I couldn’t find anything that might change the date format globally.
Sure, you could change it for Nautilus or Evolution in their respective Preferences dialogboxes. But where is the global one setting to rule them all? Thus, my hunt online began. Surprisingly, this “problem” was not well known and it took a bit of digging before I find the fix. Previously, I posted about the less than stellar format thumbdrive use case. In my opinion, here then is another fundamental use case that Ubuntu failed to provide adequately.
Now, there could be argument that I am missing the point. To explain this, we need to understand how the date format is determined in an Ubuntu system.
In Ubuntu (and possibly many Linux systems; I am not an expert here), a number of settings like location, language, timezone, time and date format, etc are lumped into what is called locale. Each country and/or region in the world is assigned a specific locale. You can find out what locale is assigned to your Ubuntu installation by typing this in the command line:
For example, this is what I get for my system:
LANG=en_SG.UTF-8 LC_CTYPE="en_SG.UTF-8" LC_NUMERIC="en_SG.UTF-8" LC_TIME="en_SG.UTF-8" LC_COLLATE="en_SG.UTF-8" LC_MONETARY="en_SG.UTF-8" LC_MESSAGES="en_SG.UTF-8" LC_PAPER="en_SG.UTF-8" LC_NAME="en_SG.UTF-8" LC_ADDRESS="en_SG.UTF-8" LC_TELEPHONE="en_SG.UTF-8" LC_MEASUREMENT="en_SG.UTF-8" LC_IDENTIFICATION="en_SG.UTF-8" LC_ALL=
So, being located in Singapore, my locale has been set to “en_SG”. Somewhere deep in the system, this designation will determine how the date is formatted (plus other things). If, for example, the date format is incorrect, the proper process is to file a bug to get it corrected in the next patch. All is good.
Well, technically. Things such as location is fixed. “en_SG” is assigned to location Singapore, no argument there. But not everyone has the same preference on how they want the date format to be. In one locale of many users, there is bound to be different preferences. Not allowing easy customisation here is basically silly.
Until this is fixed (if ever), there is no intuitive way to change the date format. But like many things Linux, workaround is entirely possible.
By default, here is how the date/time appeared in Nautilus for my system:
To change the date format, you edit the corresponding file under “/usr/share/i18n/locales/”. For my locale, it’s “/usr/share/i18n/locales/en_SG”.
gksudo gedit /usr/share/i18n/locales/en_SG
First, change the date/time format. Locate the keyword “d_t_fmt”. Here is how it appeared in my system:
% Appropriate date and time representation % %A %d,%B,%Y %I:%M:%S %Z d_t_fmt "<U0025><U0041><U0020><U0025><U0064><U002C><U0025><U0042><U002C> <U0025><U0059><U0020><U0025><U0049><U003A><U0025><U004D><U003A> <U0025><U0053><U0020><U0025><U0070><U0020><U0025><U005A>"
Make sure that the d_t_fmt line remains a single line (I have to break it up here into multiple lines for illustration because it’s too long).
This looks more complicate than it actually is. The codes are equivalent ASCII characters codes (UTF8 to be precise). You can decode it by referring to the tables here.
I would like to change the full weekday and month names to the abbreviated names. Monday becomes “Mon”, Tuesday becomes “Tue”, etc. And January becomes ‘Jan”, February becomes “Feb”, etc. I am also replacing the commas with spaces.
To do so, I change the “d_t_fmt” to:
% Appropriate date and time representation % %a %d %b %Y %I:%M:%S %Z d_t_fmt "<U0025><U0061><U0020><U0025><U0064><U0020><U0025><U0062><U0020> <U0025><U0059><U0020><U0025><U0049><U003A><U0025><U004D><U003A> <U0025><U0053><U0020><U0025><U0070><U0020><U0025><U005A>"
Ok, that wasn’t so easy, because humans are not made to decode ASCII on-the-fly.
One more part to change: the “d_fmt”. From:
% Appropriate date representation % %A %d,%B,%Y d_fmt "<U0025><U0041><U0020><U0025><U0064><U002C><U0025><U0042><U002C> <U0025><U0059>"
% Appropriate date representation % %a %d %b %Y d_fmt "<U0025><U0061><U0020><U0025><U0064><U0020><U0025><U0062><U0020> <U0025><U0059>"
Of course, you could further modify the time format under ‘t_fmt”, if you so desire. Save and exit the text editor. Then, run this command to apply the changes:
Logout and login again to see the new settings.
Here is how the date/time appeared in Nautilus for my system afterwards:
Of course, you could skip all these hassles if you don’t mind the simpler date/time format available within Nautilus preferences.
Setting to numeral date/time representation gives you this:
After tinkering with the locale, i started looking at other things I might customise, and found the first day of the week setting. By default for my locale, the first day of the week is set to Sunday. You can see this from the panel calendar:
I’m not sure the “official” first day of the week for Singapore, but since the normal office hours here are Monday to Friday, it is more logical (and convenient) to assign Monday as the first day of the week.
To change this, edit the appropriate “/usr/share/i18n/locales/” file again. Change “first_weekday” keyword from 1 to 2:
% FIXME: found in CLDR first_weekday 2
And logout and login again. Final result:
I am realising the steps above is quite long winded for something so basic. It should be relatively straightforward to code a GUI application to do this. Not sure if I can be bordered to do this personally though.