简体   繁体   中英

Converting JSON data 24 hour time to 12 hour with Javascript

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.

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')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM