I'm trying to parse a date that's extracted via exiftool
from the metadata of MOV files. It comes in a format of e.g. 2024:05:31 20:57:23+03:00
. Even though GNU's date
has the %:z
option, and it is able to produce a timestamp in such format, it's unable to parse existing value of it:
# echo $creation_date
2024:05:31 20:57:23+03:00
# date "+%Y:%m:%d %H:%M:%S%:z"
2024:06:08 22:04:15+02:00
# date "+%Y:%m:%d %H:%M:%S%:z" -d "$creation_date"
date: invalid date ‘2024:05:31 20:57:23+03:00’
What am I missing here?
Timezone is not a problem. Year-month-day is separated with :
, which is unusual. They can be separated with -
for date
to understand them. See "DATE STRING" section in man date
. You could change them:
creation_date='2024:05:31 20:57:23+03:00'
read -r ymd rest <<<"$creation_date"
date -d "${ymd//:/-} $rest"
Use strptime
command from dateutils
if you want to give exact format specification.