javascriptdatetime

Convert Zulu time zone to a specific format with javascript?


I have a date data with Zulu time zone, for example:

2017-10-13T00:00:00Z

Is there any suggestion how to convert this kind of time to the Long Date format with Javascript- e.g: Oct 13 2017? What is the correct?

[EDIT]

For a more in-depth view of dates and times in JavaScript, you can read: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date


Solution

  • You may want to use toLocaleDateString:

    let result = new Date().toLocaleDateString('en-US', {
      year: 'numeric',
      month: 'short',
      day: 'numeric',
    }).replace(',', '');
    
    console.log(result);

    For more informations see MDN