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

Slythic picture Slythic · Feb 4, 2011 · Viewed 195.7k times · Source

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.

Answer

TomTom picture TomTom · Jan 18, 2013

This is how you can change hours without if statement:

hours = ((hours + 11) % 12 + 1);