0

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.

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

Is there any way to get the output?

1 Answers1

0

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.

Allan Wind
  • 23,068
  • 5
  • 28
  • 38
  • If I add the +Format arguments to my statement, then I get date:extra operand error. But when I try it on an online compiler, it works. – Venkatesha Prasad S Feb 03 '22 at 05:26
  • You may be using a different date implementation, operating system etc. The tags you used does not tell us about your environment. Also it's not a programming question so I voted to close it. Ask on the superuser community instead. – Allan Wind Feb 03 '22 at 05:29