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.
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.
The date
program recognizes yyyy-mm-ddTHH:MM:SS
(as well as yyyy-mm-dd HH:MM:SS
), so:
a=20110724T080000Z
b=${a:0:4}-${a:4:2}-${a:6:5}:${a:11:2}:${a:13:2}
date +%F_%T -d "${b} +0"
Would print 2011-07-24_12:30:00
in my locale.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With