How to change default date and time format in linux
Linux - NewbieThis 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.
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.
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.
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.
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.
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.
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.
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.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.