How do I change the format of date
command by modifying LC_TIME
in locale?
Currently the day of month uses %e
format. I need it to be displayed in %d
format.
Below is the Current Format:
#date
Thu Aug 9 18:26:11 IST 2018
Expected format:
#date
Thu Aug 09 18:26:11 IST 2018
Here is my locale:
#locale
LANG=en_US.UTF-8
LANGUAGE=
LC_CTYPE=en_IN
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_PAPER="en_US.UTF-8"
LC_NAME="en_US.UTF-8"
LC_ADDRESS="en_US.UTF-8"
LC_TELEPHONE="en_US.UTF-8"
LC_MEASUREMENT="en_US.UTF-8"
LC_IDENTIFICATION="en_US.UTF-8"
LC_ALL=
LC_TIME
section in /usr/share/i18n/locales/en_US
:
LC_TIME
abday "Sun";"Mon";"Tue";"Wed";"Thu";"Fri";"Sat"
day "Sunday";/
"Monday";/
"Tuesday";/
"Wednesday";/
"Thursday";/
"Friday";/
"Saturday"
week 7;19971130;1
abmon "Jan";"Feb";/
"Mar";"Apr";/
"May";"Jun";/
"Jul";"Aug";/
"Sep";"Oct";/
"Nov";"Dec"
mon "January";/
"February";/
"March";/
"April";/
"May";/
"June";/
"July";/
"August";/
"September";/
"October";/
"November";/
"December"
% Appropriate date and time representation (%c)
d_t_fmt "%a %d %b %Y %r %Z"
%
% Appropriate date representation (%x)
d_fmt "%m//%d//%Y"
%
% Appropriate time representation (%X)
t_fmt "%r"
%
% Appropriate AM/PM time representation (%r)
t_fmt_ampm "%I:%M:%S %p"
%
% Strings for AM/PM
%
am_pm "AM";"PM"
date_fmt "%F %Z"
END LC_TIME
Please let me know what I can do in order to get the expected format.
NOTE: I need to execute just date
command without any formatting options.
In
LC_TIME
, there seems to be a separate way to specify the format for thedate(1)
command. This can be seen in 16.04'sen_US
locale definition:These lines are missing from 17.04 and newer's
en_US
locale definition, but is still present in theC
andPOSIX
locale files (sodate
maybe using these as a fallback).If I do edit the
en_US
locale to add adate_fmt
setting beforeEND LC_TIME
and update the locales, it works fine: