LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Set date format from 24 hrs to 12 hrs (https://www.linuxquestions.org/questions/linux-newbie-8/set-date-format-from-24-hrs-to-12-hrs-4175472441/)

yashfire007 08-07-2013 05:58 AM

Set date format from 24 hrs to 12 hrs
 
Hi to all,

I am using CentOS release 6.1.
Is there any possibility to change the date format from displaying 24hrs to 12hrs by executing 'date' command.
[root@locyes pragmatix]# date
Wed Aug 7 15:31:58 IST 2013

[root@locyes pragmatix]# hwclock
Wed 07 Aug 2013 03:32:11 PM IST -0.007036 seconds

i do want to display as 3:31:58 PM while using 'date' command. Is there any possibility.

Note: i cannot use GUI as it is a basic server installation.Please suggest me by command line..

druuna 08-07-2013 06:14 AM

The date command comes with the %r option:
Code:

date '+%r'
The above doesn't globally change the format the date/time is shown.

Date also looks at the locale setting to determine how the date/time should be shown. You can change the LC_TIME= value to reflect your preference. Try the following in a terminal:
Code:

export LC_TIME="en_US.utf8"
date

If that does what you want then adding this to your ~/.bashrc script will make it permanent.

yashfire007 08-07-2013 06:23 AM

Quote:

Originally Posted by druuna (Post 5004704)
The date command comes with the %r option:
Code:

date '+%r'
The above doesn't globally change the format the date/time is shown.

Date also looks at the locale setting to determine how the date/time should be shown. You can change the LC_TIME= value to reflect your preference. Try the following in a terminal:
Code:

export LC_TIME="en_US.utf8"
date

If that does what you want then adding this to your ~/.bashrc script will make it permanent.



I have tried your suggestion. It is still not working. please check below

[root@localhost /]# export LC_TIME="en_US.utf8"
[root@localhost /]# date
Thu Aug 8 15:57:23 IST 2013

druuna 08-07-2013 06:40 AM

I'm not entirely sure why, but it seems that you need to add '+%c' to the date command:
Code:

$ echo $LC_TIME
nl_NL.utf8

$ date
wo aug  7 12:37:03 CEST 2013

$ export LC_TIME="en_US.utf8"
$ date
Wed Aug  7 12:37:18 CEST 2013

$ date '+%c'
Wed 07 Aug 2013 12:37:23 PM CEST


yashfire007 08-07-2013 06:48 AM

Quote:

Originally Posted by druuna (Post 5004720)
I'm not entirely sure why, but it seems that you need to add '+%c' to the date command:
Code:

$ echo $LC_TIME
nl_NL.utf8

$ date
wo aug  7 12:37:03 CEST 2013

$ export LC_TIME="en_US.utf8"
$ date
Wed Aug  7 12:37:18 CEST 2013

$ date '+%c'
Wed 07 Aug 2013 12:37:23 PM CEST



Me too not sure that we are able to change the date format defaultly or not..
But one of our developer is asking me to change the date format..


All times are GMT -5. The time now is 08:46 PM.