Search code examples
linuxshelldateutc

How to convert UTC to local time in a shell script on linux


I have a string of the format

20110724T080000Z

and I want to convert that to local time in a shell script on linux. I thought I simply could give it as input to date, but I don't seem to be able to tell date what format my input date has.

this

date -d "20110724T080000Z" -u

would make date complain

date: invalid date `20110724T080000Z'

Also, what is the format of the form "20110724T080000Z" called? I have had little success trying to google for it.


Solution

  • That's ISO8601 "basic format" for a combined date and time. date does not seem to be able to parse 20110724T080000Z, but if you are prepared to do a few string substitutions it parses 20110724 08:00:00Z correctly.