XF 2.1 Converting UTC datetime to readable datetime

Cupara

Well-known member
I have this type of DateTime:
2020-10-13T22:39:00.711Z

This is in UTC and I need to convert it to:
Y-m-d i:s.u

So far I have this in my template:
HTML:
{{ date(date_from_format("Y-m-d\TH:i:s.u\Z", '{$posts.created_at}'), '') }}

How do I get this to convert and display properly? Right now it displays as Jan 1, 1970, and I'm not sure how to convert it as it's pulled in the body of the JSON call.

Thanks
 
Solution
Is the hour parameter missing in your desired format? Otherwise, your attempt is correct:

{{ date(date_from_format("Y-m-d\TH:i:s.u\Z", '2020-10-13T22:39:00.711Z'), 'Y-m-d H:i:s.u') }}

Returns this:

2020-10-13 22:39:00.711000

You just need to replace the '2020-10-13T22:39:00.711Z' with the variable name which you store that date value as string.
Is the hour parameter missing in your desired format? Otherwise, your attempt is correct:

{{ date(date_from_format("Y-m-d\TH:i:s.u\Z", '2020-10-13T22:39:00.711Z'), 'Y-m-d H:i:s.u') }}

Returns this:

2020-10-13 22:39:00.711000

You just need to replace the '2020-10-13T22:39:00.711Z' with the variable name which you store that date value as string.
 
Solution
Back
Top Bottom