Change of System Date format

I have this T5220 server with Solaris 10 installed on to it. Now when I fire the command "date" the o/p I get is as follows :

 
bash-3.00# date
Tuesday, February  9, 2010  7:25:24 PM IST

whereas I want the date to appear in this format:


bash-3.00# date
Tue Feb  9 19:26:06 IST 2010

Can anyone suggest me changes to accomplish the same.

this is my system's enviorn and locale settings :

 
root@bgw # env
MANPATH=/opt/VRTSob/man:/opt/VRTS/man:/opt/VRTSvxvm/man::/usr/man:/usr/share/man:/opt/SUNWexplo/man:/opt/SUNWsneep/man:/opt/CTEact/man:/opt/SUNWsscs/man
HZ=100
LC_MONETARY=en_US.ISO8859-1
TERM=vt100
SHELL=/sbin/sh
LC_NUMERIC=en_US.ISO8859-1
LD_LIBRARY_PATH=/usr/openwin/lib
OPENWINHOME=/usr/openwin
PATH=/usr/sbin:/usr/bin:/usr/ccs/bin:/usr/openwin/bin:/usr/dt/bin:/usr/platform/SUNW,Sun-Fire-V890/sbin:/opt/sun/bin:/etc/vx/bin:/opt/VRTS/bin:/etc/vx/bin:/opt/VRTSob/bin:/opt/VRTSvlic/bin:/opt/SUNWexplo/bin:/opt/SUNWsneep/bin:/opt/CTEact/bin:/opt/rsc/bin
MAIL=/var/mail/root
LC_MESSAGES=C
LC_COLLATE=en_US.ISO8859-1
PWD=/usr/bin
EDITOR=vi
TZ=Asia/Calcutta
PS1=root@bgw # 
PS2=root@bgw > 
SHLVL=1
HOME=/
LOGNAME=root
LC_CTYPE=en_US.ISO8859-1
LC_TIME=en_US.ISO8859-1
_=/usr/bin/env
OLDPWD=/
 
root@bgw # locale
LANG=
LC_CTYPE=en_US.ISO8859-1
LC_NUMERIC=en_US.ISO8859-1
LC_TIME=en_US.ISO8859-1
LC_COLLATE=en_US.ISO8859-1
LC_MONETARY=en_US.ISO8859-1
LC_MESSAGES=C
LC_ALL=

On my OpenSolaris 10 , locale is "C" .
and the date output is what you want .

What is "system date format" in the application context? You should always use formatting when parsing/displaying the date.

date +%Y%M%D

Use "--help" to get list of the available format patterns. Avoid assumptions that the LANG has some predefined value as it is very error prone.

The default date format is part of the locale -

And, no, you do not necessarily need to use formatting every time you use the date command. If you need output which does not match the default for your current locale then you can either change your locale setting by redefining the LC_TIME environment variable or using formatting strings.

Something else is odd in the OP's envrironment. You can create custom envrionments
-- en_US.ISO8859-1 is standard AFAIK. So on an untweaked system:

worx> locale
LANG=
LC_CTYPE="C"
LC_NUMERIC="C"
LC_TIME="C"
LC_COLLATE="C"
LC_MONETARY="C"
LC_MESSAGES=C
LC_ALL=C

worx> date
Tue Feb 16 13:54:13 MST 2010

worx> export LC_TIME=LC_TIME=en_US.ISO8859-1

worx> date
Tue Feb 16 13:54:24 MST 2010


worx> export LC_ALL=en_US.ISO8859-1
worx> locale
LANG=
LC_CTYPE=en_US.ISO8859-1
LC_NUMERIC=en_US.ISO8859-1
LC_TIME="en_US.ISO8859-1"
LC_COLLATE=en_US.ISO8859-1
LC_MONETARY=en_US.ISO8859-1
LC_MESSAGES="en_US.ISO8859-1"
LC_ALL=en_US.ISO8859-1

worx> date
Tue Feb 16 13:55:46 MST 2010

The locale defined for LC_TIME in en_US.ISO8859-1 does not vary from locale == C. At least on an out-of-the-box Solaris install. Somebody has customized that locale file on the OP's box. IMO.

1 Like