LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 08-07-2013, 04:58 AM   #1
yashfire007
Member
 
Registered: Jan 2013
Distribution: CentOS, RHEL 6.4
Posts: 79

Rep: Reputation: Disabled
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..
 
Old 08-07-2013, 05:14 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389
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.
 
Old 08-07-2013, 05:23 AM   #3
yashfire007
Member
 
Registered: Jan 2013
Distribution: CentOS, RHEL 6.4
Posts: 79

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by druuna View Post
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
 
Old 08-07-2013, 05:40 AM   #4
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389
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
 
Old 08-07-2013, 05:48 AM   #5
yashfire007
Member
 
Registered: Jan 2013
Distribution: CentOS, RHEL 6.4
Posts: 79

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by druuna View Post
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..
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
fileListing command for last 24 hrs mech123 Linux - Newbie 8 05-10-2010 11:51 PM
24 hrs TimeZone santhosh23 Linux - General 1 11-05-2007 02:27 PM
less than 24 hrs into linux and i already broke something lejakl Linux - Software 7 07-31-2003 10:47 AM
Disconnect after 2 hrs on idle bernstar77 Linux - Networking 0 11-26-2001 01:37 PM
Clock 4 hrs off at start up mike L Linux - General 13 07-16-2001 07:17 AM


All times are GMT -5. The time now is 07:47 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration