Search code examples
javascriptdatedate-format

How to format a date to "E, d MMM yyyy HH:mm:ss zzz" in javascript?


I have a string date like this:

2018-08-26T00:00:00.000Z

Is there a way that I can format it so it looks similar to this format?

Fri, 24 Aug 2018 09:30:00 GMT 
E, d MMM yyyy HH:mm:ss zzz

Solution

  • Simply construct a Date object, and then you can use Date.prototype.toUTCString to format the string in the GMT format:

    var date = new Date('2018-08-26T00:00:00.000Z');
    console.log(date.toUTCString());