Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to get IST in Unix if my current timezone is UTC. Also I need to get the time format to be dd/mm/yyyy hr:min:sec?

I have just started learning about the date command in Unix.
I have typed the below code to get the IST. But I don’t know how to convert it to a specific format.

TZ = IST-5:30 date

This gives the result as Thu Feb 10:31:51 IST 2022.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

But I want the output to be 03/02/2022 10:31:51 IST.

Is there any way to get the output?

>Solution :

With date (GNU coreutils) 8.32 you can use the +FORMAT argument:

TZ=IST-5:30 date +'%d/%m/%y %T %Z'
03/02/22 10:46:50 IST

%x would be a better choice instead of %d/%m/%y if your locale allows for it.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading