Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Converting 24 hour time to 12 hour time w/ AM & PM using Javascript

What is the best way to convert the following JSON returned value from a 24-hour format to 12-hour format w/ AM & PM? The date should stay the same - the time is the only thing that needs formatting.

February 04, 2011 19:00:00 

P.S. Using jQuery if that makes it any easier! Would also prefer a simple function/code and not use Date.js.

like image 866
Slythic Avatar asked Feb 04 '11 13:02

Slythic


1 Answers

This is how you can change hours without if statement:

hours = ((hours + 11) % 12 + 1); 
like image 159
TomTom Avatar answered Oct 14 '22 10:10

TomTom