-1

I know there are many functions in javascript that changes the date format, but I want to change the format of the string.

How can I change

2018-05-10T21:12:08Z

to

2018-05-10 9:12:08 AM

The date function doesn't work since it's not a date type.

Dawn17
  • 7,825
  • 16
  • 57
  • 118
  • I would probably get each part of the date individually first. (year/month/day) then get the time (h:m:s) then get the am/pm part. That way you can format each part and then concatenate them much easier. Start here: https://www.w3schools.com/js/js_date_formats.asp – Kevin Marmet May 11 '18 at 15:45
  • Look into `Date.parse()` first, or you can use an external library like `moment.js` – ionizer May 11 '18 at 15:46
  • Turn the string into a `Date`, turn the `Date` into a string… – deceze May 11 '18 at 15:47

1 Answers1

0

You can use moment library to do all kind of date/time operations.

var dt = moment('2018-05-10T21:12:08Z');
console.log(dt.format('YYYY-MM-DD h:mm:ss A'));
Ubaid
  • 431
  • 4
  • 14