Tuesday, March 13, 2012

Custom Dates

In this month's Full Circle Magazine I wrote about some tips and tricks I use (Command & Conquer), but I felt I would share this small script here as well, since others may find it useful.

The idea behind the script is to create a time display in a different locale (in this case, Japanese). I've ignored the "usual" format for dates in Japan, opting instead for the usual display (Day, date, time), and as such I had to format it a bit differently with date. The script is as follows:

 #!/bin/sh 
LC_ALL="" LC_TIME=ja_JP.UTF-8 date +'%A, %-d日%B%Y年 %H:%M'
This script does require you to generate the ja_JP.UTF-8 locale (or, at least, it was required for my system). Since it varies from distribution to distribution, I'll leave that unexplained for now. I essentially make sure LC_ALL is set to nothing (messes up the custom locale otherwise), and then I set the locale for time to Japanese. Then I print out a formatted date of day, date, month, year, time. I was forced to add in the Kanji for day and year, as it wasn't filled in by date itself (no idea why). However, it results in a nice clock, and offers me a bit of practice in Japanese.

No comments: