Guide to setting custom date format in (recent versions of) KDE
Guide to setting custom date format in (recent versions of) KDE
So I was looking for a way to customize the date format displayed in Dolphin in KDE on my Kali system but it doesn't seem the setting is easily changed. This is managed by locales but none of the preinstalled ones seemed to affect the setting I was trying to change in the way that I wanted it. (That's not to say I didn't overlook it) So! If there is already an easy way to do this, please, call me an idiot and say "Click here next time". But until then, there doesn't seem to be a very straightforward guide on how to do it. So for a future reference for myself, and anyone else trying to do the same or similar, just follow along. I may add more information about settings that weren't important for me to change, but you may be interested in them. So far, I have tried this and it has worked on Kali Linux 2016.2 rolling KDE Plamsa Version: 5.8.2 KDE Frameworks Version: 5.27.0 QT Version: 5.7.1 Kernel Version: 4.8.0-kali2-amd64 OS Type: 64 bit Kubuntu 16.10 KDE Plamsa Version: 5.7.5 KDE Frameworks Version: 5.26.0 QT Version: 5.6.1 Kernel Version: 4.8.0-30-generic OS Type: 64 bit Specifically, what I am trying to change is the Date format to display DAY(number)/SHORTMONTH(text)/YEAR(number) e.g. 31/JAN/2016 rather than the default (at least, on my installation) MONTH(number)/DAY(number)/YEAR(number) e.g. 31/1/2016 I was going to upload a picture but it seems I can't. Here is a link The process is not that long or difficult, but because we are editing files that aren't very human-readable, please be careful of the commands you enter into your terminal The files we will be dealing with are located in (currently): * /usr/share/i18n/locales/ (For CentOS/Rhel etc. I believe it is located in /usr/sysconfig/i18n/locales/) * /etc/locale.gen Let's go ahead and view our current locale settings Code:
locale The first thing you'll want to do is cd to the proper directory for your system Code:
cd /usr/share/i18n/locales Code:
cp en_US custom Next, we will be editing this file, however, as I mentioned before, it's not particularly human-readable. So we will need to know a few things before hand. To get an idea of what I mean, go ahead and Code:
cat custom You'll notice the code at the end of the file is rather difficult to decipher. The particular part I'll be editing is in the section LC_TIME, though the process is (relatively) the same for any other changes you'd like to make. Specfically, the line I'll be editing starts with d_fmt and is responsible for the date format. Let's go ahead and Code:
cat custom | grep -B2 d_fmt Here, in the middle line, is the human-readable(er) format of our date. The arguments here %m/%d/%Y are just to help us out. Note that in this file, lines beginning with % indicate a comment and the rest of the line is ignored when the file is read. But let's do the first of a couple steps to deciphering exactly what the d_fmt line means, so that we know what we're editing. We can find the meaning of the arguments that are more human-readable in the date manual. Look for FORMAT and you should a list of characters and their meanings. Code:
man date From here we find (well, you probably could've guessed what these stood for, but other options aren't as easily guessed :D) that %m/%d/%Y translates to month(1...12) day of month (e.g., 01) year and I want it to be day of month (e.g., 01) shortmonth (e.g. Jan, Feb, Mar, etc) year or, %d/%b/%Y where %b gives us our abbreviated month name. Now we have one more step before this is useable for us, the d_fmt line that we are actually editing is really just our %m/%d/%Y but written in hexadecimal unicode. A conversion table can be found here. Now I know I want to change my %m to %b, and rearrange so that DAY comes before SHORTMONTH. After a little bit of effort, the "%d/%b/%Y" format that I want turns into <U0025><U0064><U002F><U0025><U0062><U002F><U0025><U0059> *Note: you may want to edit the %m/%d/%Y as well to reflect the changes you made, just for yourself in the future You'll quickly see that this can be a time consuming and involved process when done by hand, depending on how many changes you want to make. Luckily, we can save ourselves a bit of time if you have uni2ascii installed. This can be done character by character or all at once. Just determine the format that you'd like in the more human-readable format, in my case, that's %d/%b/%Y. The conversion command is uni2ascii -a A -p. This gives us our string in exactly the format we want. This will give us a blinking cursor on the line below to enter our string. Note that any spaces will be converted literally! Code:
uni2ascii -a A -p So I'm going to Code:
vim /usr/share/i18n/locales/custom Code:
:/d_fmt (use h and l (lowercase L) to move the cursor left or right, and j or k to move down or up) Go ahead and higlight the first angle bracket with your cursor and press Code:
dt" If you want to make any other changes, the process is the same, go ahead and make them now, edit commands as necessary for your particular situation. *Note that the only change I tested is the one mentioned above! The information below is just information I gathered throughout the process and writing this guide! If any changes you make don't seem to work properly, I will do my best to help you out. Also, note that other options are available apart from the ones I explicitly mention, study the man date FORMAT section to figure out your options. Other notable sections in LC_TIME include: Code:
cat custom | grep -B2 d_t_fmt U0061=a (abbreviated weekday name (e.g., Sun)) U0020=" " U0025=% U0064=d (day of month (e.g., 01)) U0020=" " U0025=% U0062=b (abbreviated month name (e.g., Jan)) U0020=" " U0025=% U0059=Y (year U0020=" " U0025=% U0072=r (12-hour clock time (e.g., 11:11:04 PM)) U0020=" " U0025=% U005A=Z (alphabetic time zone abbreviation (e.g., EDT)) Code:
cat custom | grep -B2 am_pm Code:
cat /usr/share/i18n/locales/custom | grep -B2 -A1 t_fmt_ampm U0025=% U0049=I (uppercase i) (hour 1...12) U003A=: U0025=% U004D=M (minute 0..59) U003A=: U0025=% U0053=S (second 00..59) U0020=" " (a literal space) U0025=% U0070=p *If you want a 24 hour clock format, change the "I" (0049) here to "H" (0048), if you want lowercase am/pm change the "p" (0070) here to "P" (0050) Code:
cat /usr/share/i18n/locales/custom | grep -B2 t_fmt There are many other sections but for the sake of keeping this a (relatively) short guide, I'm only going to mention the rest and their basic functions and leave it to you to do for more granular control. abday Defines the abbreviated weekday names corresponding to the %a field descriptor day Defines the full spelling of the weekday names corresponding to the %A field descriptor abmon Defines the abbreviated month names corresponding to the %b field descriptor mon Defines the full spelling of the month names corresponding to the %B field descriptor That's it for LC_TIME. Changes in other locale arguments (e.g. LC_CTYPE, LC_NUMERIC, LC_ADDRESS, etc) can be made similarly. A brief summary of some of them and their purpose can be found at the end. Code:
vim /etc/locale.gen Code:
custom.UTF-8 UTF-8 Code:
local-gen Code:
export LC_TIME=custom.UTF-8 On the other hand, I can also use my custom as the system default Code:
dpkg-reconfigure locales You may have to logout and login for the changes to take affect. Now lets open Dolphin and take a look at the date And here we see the change! and just for good measure, let's check out locale Code:
locale That's it! Enjoy your new date format |
Member response
Hi,
Thanks for sharing. :hattip: |
I couldn't get this working on Neon (plasma 5.10). The custom locale doesn't show up in the `Formats` system settings dialog. I also tried modifying the existing locale I'm using but, that didn't take effect either.
|
Link to another guide out there for those who want more.
how-to-change-date-formats-on-ubuntu
Basically says the same things that are posted here. Reading the comments on this might help those that want more information. |
Quote:
Code:
unset LC_ALL |
Sample Codes
You can use lines like the following to help create your new format lines:
Where "$@" is the string you want to convert; 'space' separated items, if you want a 'space' manually add the '<U0020>' to the output where you want it.(or you could change this script) Code:
echo \""$(echo "$@" | uni2ascii -a A -p | sed 's/ /";"/g')"\" Here's some examples ... Uncomment lines you want to use... Code:
% Abbreviation for months of years Code:
% Date time format Code:
% Strings for am_pm: Code:
% LC_MESSAGES Code:
% LC_TELEPHONE |
To test out LC_TIME
If you want to test out if your LC_TIME is working and set, run the date command.
If your custom LC_TIME is working and set, then this code's output should match the formatting you gave to LC_TIME. Code:
man date | grep locale Code:
date +"%a%n%A%n%b%n%B%n%c%n%p%n%r%n%x%n%X" |
Hi!
I'm using the extension Clock Override to format my top bar datetime in Ubuntu 18.04. I'm using %A to display my locale's (Norwegian) full weekday, and while it is correct that weekdays are lowercase in Norwegian ("søndag"), I would like to have it capitalized in the top bar datetime ("Søndag"). Is there any way I can achieve this? I have been googling for hours without finding anything useful. :-( Thanks in advance! Edit: I'm sorry, I didn't see the sticky until after I posted. I have now created my own thread in the N00b-forum. Please ignore this post. |
All times are GMT -5. The time now is 01:29 AM. |