Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Using Date() to convert ISO 8601 time to UTC

  • Using Date() to convert ISO 8601 time to UTC

    Posted by Nickolas Howell on September 25, 2018 at 12:43 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

    Terje Lundgren replied 7 years, 7 months ago 3 Members · 6 Replies
  • 6 Replies
  • Kalleheikki Kannisto

    September 25, 2018 at 3:59 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

  • Nickolas Howell

    September 25, 2018 at 10:44 pm

    Thank you!

    What a great catch!

  • Nickolas Howell

    September 25, 2018 at 10:52 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?

  • Kalleheikki Kannisto

    September 26, 2018 at 6:12 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

  • Kalleheikki Kannisto

    September 26, 2018 at 8:08 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

  • Terje Lundgren

    October 3, 2018 at 1:16 pm

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

    /Terje

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy