Assuming the timezone is always in the format GMT-nn
, something like this could work to shuffle the fields around for the GNU version of date
and date -d
:
a="GMT-08-2021.08.31-18.29.05"
b=$(echo "$a" | sed -E -e 's/GMT([-+][0-9]+)-([0-9]+)\.([0-9]+)\.([0-9]+)-([0-9]+)\.([0-9]+)\.([0-9]+)/\2-\3-\4 \5:\6:\7 \100/')
date -u -d "$b"
That's basically just a bunch of capture groups ((...)
) and putting them back in the right order (\2
for the second group, etc.).
With that example value, b
would contain 2021-08-31 18:29:05 -0800
, and I get Wed Sep 1 02:29:05 UTC 2021
from date
.
For other versions of date
, you'd need some other output format.