Convert iso8601_micro date format into local date/time and local timezone

Latest response

Hello.

I've been racking my brain on this and unable to find any samples of how to convert iso8601_micro date/time format into my localtime with timezone. I've been able to convert it as far as getting the UTC value but I need to make it so it shows the local time convert to locall timezone.

I'm basically taking this value from tower to show when a host was created in an inventory so I can either keep it there or delete it. If anyone has any great ideas please come forward!

Thank you.

Glen

Responses

Hi Glen,

I hope I understand your question correctly.

There are many ways to convert ISO8601 to standard time.

Here is one Bash-style example:

iso8601var="2021-05-13T10:52:44+10:00"
timeZone="Australia/Sydney"
loctime=$(date -d"TZ=\"${timeZone}\" $var")
echo $loctime

Regards,

Dusan Baljevic (amateur radio VK2COT)

Hello. Thanks for the reply. And I feel stupid.....I left out one important bit of information. I'd like to do this is native ansible. This date/time format is an internal field in the ansible tower inventory which I can to do some comparisons against. There is no jinga template built into ansible that will convert the iso format. At least not that I have found.

Thanks,

Glen