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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
05-02-2017, 12:40 PM
|
#1
|
LQ Newbie
Registered: Mar 2017
Location: Pune
Distribution: Redhat,Ubuntu,Centos
Posts: 6
Rep: 
|
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
|
|
|
05-02-2017, 12:50 PM
|
#2
|
LQ Guru
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,831
|
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.
|
05-02-2017, 12:56 PM
|
#3
|
LQ Newbie
Registered: Mar 2017
Location: Pune
Distribution: Redhat,Ubuntu,Centos
Posts: 6
Original Poster
Rep: 
|
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
|
|
|
05-02-2017, 01:25 PM
|
#4
|
Senior Member
Registered: Dec 2003
Location: The Key Stone State
Distribution: CentOS Sabayon and now Gentoo
Posts: 1,249
Rep: 
|
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.
|
05-02-2017, 01:59 PM
|
#5
|
LQ Guru
Registered: Nov 2008
Location: Pictland
Distribution: Linux Mint 21 MATE
Posts: 8,048
|
Quote:
Originally Posted by MensaWater
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.
|
05-02-2017, 02:20 PM
|
#6
|
Moderator
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,968
|
Quote:
Originally Posted by Nandhu_mnk
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
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
I think date +'%a %-d %b %Y %H:%M:%S %Z' would more accurately match the OP's requirements.
|
|
|
|
05-02-2017, 02:26 PM
|
#7
|
LQ Veteran
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Rep: 
|
Quote:
Originally Posted by Nandhu_mnk
but i want to get below default format while only using date command.
|
in your ~/.bashrc
save your work and logout and back in.
Last edited by Habitual; 05-02-2017 at 02:28 PM.
|
|
|
05-02-2017, 02:32 PM
|
#8
|
LQ Guru
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,831
|
Quote:
Originally Posted by Habitual
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.
|
|
|
05-02-2017, 02:33 PM
|
#9
|
LQ Guru
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,831
|
Quote:
Originally Posted by hydrurga
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.
|
|
|
05-02-2017, 03:30 PM
|
#10
|
LQ Guru
Registered: Nov 2008
Location: Pictland
Distribution: Linux Mint 21 MATE
Posts: 8,048
|
Quote:
Originally Posted by MensaWater
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. 
|
|
|
05-02-2017, 03:36 PM
|
#11
|
LQ Veteran
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Rep: 
|
Quote:
Originally Posted by MensaWater
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
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.
|
|
|
05-02-2017, 03:49 PM
|
#12
|
LQ Guru
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,831
|
Quote:
Originally Posted by Habitual
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.
|
|
|
05-02-2017, 04:50 PM
|
#13
|
LQ Guru
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 27,808
|
Quote:
Originally Posted by MensaWater
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.
|
|
|
05-05-2017, 12:57 AM
|
#14
|
LQ Guru
Registered: Aug 2016
Location: SE USA
Distribution: openSUSE & OS/2 24/7; Debian, Knoppix, Mageia, Fedora, others
Posts: 6,599
|
Quote:
Originally Posted by Habitual
|
Were you perhaps thinking of a change in LOCALE when you wrote TZ?
|
|
|
05-05-2017, 01:50 AM
|
#15
|
Member
Registered: Jan 2017
Location: Fremont, CA, USA
Distribution: Trying any&ALL on old/minimal
Posts: 997
|
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.
|
|
|
All times are GMT -5. The time now is 06:08 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|