-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.

3
  • 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: w3schools.com/js/js_date_formats.asp Commented May 11, 2018 at 15:45
  • Look into Date.parse() first, or you can use an external library like moment.js Commented May 11, 2018 at 15:46
  • Turn the string into a Date, turn the Date into a string… Commented May 11, 2018 at 15:47

1 Answer 1

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'));
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.