LinuxQuestions.org
Visit Jeremy's Blog.
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 05-02-2017, 12:40 PM   #1
Nandhu_mnk
LQ Newbie
 
Registered: Mar 2017
Location: Pune
Distribution: Redhat,Ubuntu,Centos
Posts: 6

Rep: Reputation: Disabled
Question How to change default date and time format in linux


Hi friends,
Normally my linux machine giving this below date and time formate while using date command.

[root@wadisvr ~]# date
Wed May 3 04:35:19 IST 2017


but i want to get below default format while only using date command.
[root@wadisvr ~]# date
Wed 3 May 2017 04:35:19 IST


please guide me for the abouve problem.

Regards,
Nandhu_mnk
 
Old 05-02-2017, 12:50 PM   #2
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,831
Blog Entries: 15

Rep: Reputation: 1668Reputation: 1668Reputation: 1668Reputation: 1668Reputation: 1668Reputation: 1668Reputation: 1668Reputation: 1668Reputation: 1668Reputation: 1668Reputation: 1668
If you type "man date" it will show details of the usage for date command including the FORMAT.

The "default" is what you see but you can get what you want by using a FORMAT specification:

date +"%a %d %b %Y %H:%M %Z"
 
2 members found this post helpful.
Old 05-02-2017, 12:56 PM   #3
Nandhu_mnk
LQ Newbie
 
Registered: Mar 2017
Location: Pune
Distribution: Redhat,Ubuntu,Centos
Posts: 6

Original Poster
Rep: Reputation: Disabled
thanks friend,

I tried that format option also.But my linux application team asking to change default date and time format.
while simply i type that date command it should give that (Wed 3 May 2017 04:35:19 IST )format date and time.
i should never use anything in in that command's option.

regards,
Nandhu_mnk
 
Old 05-02-2017, 01:25 PM   #4
lazydog
Senior Member
 
Registered: Dec 2003
Location: The Key Stone State
Distribution: CentOS Sabayon and now Gentoo
Posts: 1,249
Blog Entries: 3

Rep: Reputation: 194Reputation: 194
I'm not sure this is possible without modifying the code.
Have you tried to make an alias for date?

Code:
alias date="date +'%a %d %b %Y %H:%M %Z'"
You could add it to your users bashrc or bash_profile file so that when they logs in it is set automatically.

Last edited by lazydog; 05-02-2017 at 01:28 PM.
 
2 members found this post helpful.
Old 05-02-2017, 01:59 PM   #5
hydrurga
LQ Guru
 
Registered: Nov 2008
Location: Pictland
Distribution: Linux Mint 20 MATE
Posts: 8,048
Blog Entries: 5

Rep: Reputation: 2916Reputation: 2916Reputation: 2916Reputation: 2916Reputation: 2916Reputation: 2916Reputation: 2916Reputation: 2916Reputation: 2916Reputation: 2916Reputation: 2916
Quote:
Originally Posted by MensaWater View Post
If you type "man date" it will show details of the usage for date command including the FORMAT.

The "default" is what you see but you can get what you want by using a FORMAT specification:

date +"%a %d %b %Y %H:%M %Z"
I think date +'%a %-d %b %Y %H:%M:%S %Z' would more accurately match the OP's requirements.
 
1 members found this post helpful.
Old 05-02-2017, 02:20 PM   #6
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,314
Blog Entries: 13

Rep: Reputation: 4370Reputation: 4370Reputation: 4370Reputation: 4370Reputation: 4370Reputation: 4370Reputation: 4370Reputation: 4370Reputation: 4370Reputation: 4370Reputation: 4370
Quote:
Originally Posted by Nandhu_mnk View Post
thanks friend,

I tried that format option also.But my linux application team asking to change default date and time format.
while simply i type that date command it should give that (Wed 3 May 2017 04:35:19 IST )format date and time.
i should never use anything in in that command's option.

regards,
Nandhu_mnk
Hi Nandhu_mnk and welcome to LQ.

Please realize that commands work in native forms a certain way. As cited by lazydog, hydrurga, and MensaWater; in order to attain an exacting format for how you wish to see the date, you will have to use command modifiers to accomplish this. The suggestion to use an alias is very applicable here. There is also a notation about modifying the actual code for the date command. Which would mean that you could download the open source for the date command, edit it to reformat how it formats the output, and then compile and install the custom replacement command to have it work in a different native reporting format.

Other than those varieties of options, I do not see any way that this can work exactly as you're asking, but do please note that the output form you are seeking, is clearly available.
Quote:
Originally Posted by lazydog View Post
I'm not sure this is possible without modifying the code.
Have you tried to make an alias for date?

Code:
alias date="date +'%a %d %b %Y %H:%M %Z'"
You could add it to your users bashrc or bash_profile file so that when they logs in it is set automatically.
Quote:
Originally Posted by hydrurga View Post
I think date +'%a %-d %b %Y %H:%M:%S %Z' would more accurately match the OP's requirements.
 
Old 05-02-2017, 02:26 PM   #7
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
Quote:
Originally Posted by Nandhu_mnk View Post
but i want to get below default format while only using date command.
Code:
export TZ=IST
in your ~/.bashrc

save your work and logout and back in.

Last edited by Habitual; 05-02-2017 at 02:28 PM.
 
Old 05-02-2017, 02:32 PM   #8
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,831
Blog Entries: 15

Rep: Reputation: 1668Reputation: 1668Reputation: 1668Reputation: 1668Reputation: 1668Reputation: 1668Reputation: 1668Reputation: 1668Reputation: 1668Reputation: 1668Reputation: 1668
Quote:
Originally Posted by Habitual View Post
Code:
export TZ=IST
in your ~/.bashrc

save your work and logout and back in.
All that does is set the default time zone which presumably the OP has already done because he is already seeing IST in his output. The question was about order in output NOT which time zone to used by default.
 
Old 05-02-2017, 02:33 PM   #9
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,831
Blog Entries: 15

Rep: Reputation: 1668Reputation: 1668Reputation: 1668Reputation: 1668Reputation: 1668Reputation: 1668Reputation: 1668Reputation: 1668Reputation: 1668Reputation: 1668Reputation: 1668
Quote:
Originally Posted by hydrurga View Post
I think date +'%a %-d %b %Y %H:%M:%S %Z' would more accurately match the OP's requirements.
Yep - I missed the seconds. D'oh!

Of course I did tell the OP where to find the FORMAT options so he might have figured it out.

Lazydog's suggestion of setting up an alias would do it (for logged in users anyway - they might have to add aliases to scripts if there is something they are running). Of course his suggestion needs the :%S as well.

Last edited by MensaWater; 05-02-2017 at 02:36 PM.
 
Old 05-02-2017, 03:30 PM   #10
hydrurga
LQ Guru
 
Registered: Nov 2008
Location: Pictland
Distribution: Linux Mint 20 MATE
Posts: 8,048
Blog Entries: 5

Rep: Reputation: 2916Reputation: 2916Reputation: 2916Reputation: 2916Reputation: 2916Reputation: 2916Reputation: 2916Reputation: 2916Reputation: 2916Reputation: 2916Reputation: 2916
Quote:
Originally Posted by MensaWater View Post
Yep - I missed the seconds. D'oh!

Of course I did tell the OP where to find the FORMAT options so he might have figured it out.

Lazydog's suggestion of setting up an alias would do it (for logged in users anyway - they might have to add aliases to scripts if there is something they are running). Of course his suggestion needs the :%S as well.
and the hyphen in %-d so that there is no zero padding in the day of the month.
 
Old 05-02-2017, 03:36 PM   #11
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
Quote:
Originally Posted by MensaWater View Post
All that does is set the default time zone which presumably the OP has already done because he is already seeing IST in his output. The question was about order in output NOT which time zone to used by default.
Yep. Stepped right in it.
presumably? DFQ is that?
Quote:
Originally Posted by Nandhu_mnk View Post
Normally my linux machine giving this below date and time formate while using date command.
So what's not "normal" now?
Not much to go on.
 
Old 05-02-2017, 03:49 PM   #12
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,831
Blog Entries: 15

Rep: Reputation: 1668Reputation: 1668Reputation: 1668Reputation: 1668Reputation: 1668Reputation: 1668Reputation: 1668Reputation: 1668Reputation: 1668Reputation: 1668Reputation: 1668
Quote:
Originally Posted by Habitual View Post
Yep. Stepped right in it.
presumably? DFQ is that?

So what's not "normal" now?
Not much to go on.
In essence he is asking how to put the time zone (IST) at end of line for "date" command output instead of where it appears by default.
 
Old 05-02-2017, 04:50 PM   #13
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 23,806

Rep: Reputation: 6973Reputation: 6973Reputation: 6973Reputation: 6973Reputation: 6973Reputation: 6973Reputation: 6973Reputation: 6973Reputation: 6973Reputation: 6973Reputation: 6973
Quote:
Originally Posted by MensaWater View Post
In essence he is asking how to put the time zone (IST) at end of line for "date" command output instead of where it appears by default.
Given that he posted this:
Quote:
Originally Posted by Nandhu_mnk
I tried that format option also.But my linux application team asking to change default date and time format.
...I'd say (given that he says he's the Linux administrator), tell the 'application team' to write an application to do it the way they want to.

Nandhu_mnk, what is it that your 'application team' is trying to accomplish with this? What's your real goal? Because if your developers can't figure out how to format a date in any way they see fit...it's time to hire new developers.
 
Old 05-05-2017, 12:57 AM   #14
mrmazda
Senior Member
 
Registered: Aug 2016
Location: USA
Distribution: openSUSE, Debian, Knoppix, Mageia, Fedora, others
Posts: 3,255
Blog Entries: 1

Rep: Reputation: 1102Reputation: 1102Reputation: 1102Reputation: 1102Reputation: 1102Reputation: 1102Reputation: 1102Reputation: 1102Reputation: 1102
Quote:
Originally Posted by Habitual View Post
Code:
export TZ=IST
in your ~/.bashrc
Were you perhaps thinking of a change in LOCALE when you wrote TZ?
 
Old 05-05-2017, 01:50 AM   #15
!!!
Member
 
Registered: Jan 2017
Location: Fremont, CA, USA
Distribution: Trying any&ALL on old/minimal
Posts: 747

Rep: Reputation: 323Reputation: 323Reputation: 323Reputation: 323
Maybe edit t_fmt in /usr/share/i18n/locale/$LC_TIME per this
(from 3rd result from googling thread title; add intitle:globally to make it 1st)

Last edited by !!!; 05-05-2017 at 02:20 AM.
 
  


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
LXer: How to Change the Linux Date and Time: Simple Commands LXer Syndicated Linux News 1 10-13-2012 12:07 PM
LXer: How to change Thunderbird's date format in Date column LXer Syndicated Linux News 0 07-18-2012 02:11 AM
Linux RedHat: How to change system date/time? dijonez@gmail.com Linux - Newbie 2 10-10-2011 06:06 AM
C code to change date time on linux mayankparasher Programming 5 03-31-2009 10:04 PM
How do I set default Currency , Date format anilbh Fedora 3 07-05-2006 09:35 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

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

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
Open Source Consulting | Domain Registration