0

The JSON I'm pulling returns the time and date information together in this format:

06-16-2013 16:00:00

What I need to do is convert it from 24 hour time to 12 hour time (with AM and PM, preferably). I've seen similar posts and functions on here, but none that seem to work with this particular formatting (here is one good example).

My JavaScript isn't superb, which might be part of the problem when it comes to getting other functions to work for me.

2
  • think about a javascript date-time library like momentjs Commented Jun 17, 2013 at 2:58
  • Note: JavaScript only officially supports a simplified ISO 8601 Extended Format: YYYY-MM-DDTHH:mm:ss.sssZ. Other formats can be supported by an individual JavaScript engine, but the exact list of formats varies from one engine to another. Commented Jun 17, 2013 at 3:05

1 Answer 1

1

You can use momentjs to format the date in the way you prefer. First include momentjs http://momentjs.com/ in your project, and then you will be able to do:

moment('06-16-2013 16:00:00','MM-DD-YYYY HH:MM:SS').format('MM-DD-YYYY hh:mm:ss a')
Sign up to request clarification or add additional context in comments.

1 Comment

Note that the capital "MM" is for Months not Minutes.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.