ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Using Date() to convert ISO 8601 time to UTC

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Nickolas Howell
Using Date() to convert ISO 8601 time to UTC
on Sep 25, 2018 at 12:43:44 am

Hey everyone!

I'm trying to convert ISO 8601 dates I have to readable dates with expressions.
So far I've been able to get the current date and print it with this:

date = new Date(0);
parsed = date.toString().split(" ").slice(1, 4).join(", ");
parsed;

outputs the date as Sep, 24, 2018.


However, when I try to plug in my ISO 8601 format time...

text = "2018-08-06T00:00:00.000Z";
date = new Date(text);
parsed = date.toString();

parsed;


I get : "Invalid Date" as my return value.

Does anybody here see any immediate flaws or have some advice for me?

Thanks,
Nick


Return to posts index

Kalleheikki Kannisto
Re: Using Date() to convert ISO 8601 time to UTC
on Sep 25, 2018 at 3:59:22 pm

Not all that familiar with javascript date method limitations, but this works for me:

txt = "2018-08-06T00:00:00";
date = new Date(txt);
parsed = date.toString();
parsed


The first issue was using a reserved variable "text", which the AE tries to interpret as the text content of the layer.

The second seems to be the formatting of the date with milliseconds, taking those out handled the error message.

Kalleheikki Kannisto
Senior Graphic Designer


Return to posts index

Nickolas Howell
Re: Using Date() to convert ISO 8601 time to UTC
on Sep 25, 2018 at 10:44:59 pm

Thank you!

What a great catch!


Return to posts index


Nickolas Howell
Re: Using Date() to convert ISO 8601 time to UTC
on Sep 25, 2018 at 10:52:20 pm

Unfortunately, on my end this appears to return:

Mar 09 1912 00:00:00 GMT-0700

instead of the correct date:

Mon, 6 Aug 2018 00:00:00 -06:00

Are you getting the correct date on your side?


Return to posts index

Kalleheikki Kannisto
Re: Using Date() to convert ISO 8601 time to UTC
on Sep 26, 2018 at 6:12:13 am

Hi, yes, how the heck did I miss that? It gives the same wrong output date at my end. Talk about looking at the details to miss the big picture. I don't have an immediate answer to as to why, but I can take a look if I can find something that would explain it.

Kalleheikki Kannisto
Senior Graphic Designer


Return to posts index

Kalleheikki Kannisto
Re: Using Date() to convert ISO 8601 time to UTC
on Sep 26, 2018 at 8:08:49 am
Last Edited By Kalleheikki Kannisto on Sep 26, 2018 at 8:15:20 am

Finding no explanation as to why the other input format doesn't work in AE, but inputting the date in this format works:

txt = "August 6, 2018 00:00:00";
date = new Date(txt);
parsed = date.toString();
parsed


I realize that doesn't really help much with your original issue. Unless someone knows a better way, it looks like you will have to write a more complex expression to convert the ISO 8601 time to the desired format.

Kalleheikki Kannisto
Senior Graphic Designer


Return to posts index


Terje Lundgren
Re: Using Date() to convert ISO 8601 time to UTC
on Oct 3, 2018 at 1:16:10 pm

I've heard momentjs is a good library for working with dates. Maybe you'll find a solution there..
http://momentjs.com/docs/#/parsing/

/Terje


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2018 CreativeCOW.net All Rights Reserved
[TOP]