I am scraping JSON data from a url. The time is military time and I was wondering if there is a way once I retrieve on the client side to convert it to standard time.
<
"Military time" (a.k.a. 24-hour time) is easily converted to 12-hour time via a simple modulo 12.
JSFiddle example:
var obj = {
SaturdayClose: "21:00",
SaturdayOpen: "10:00",
SundayClose: "12:00",
SundayOpen: "18:00",
WeekdayClose: "21:00",
WeekdayOpen: "10:00"
}, prop, $output = $('#output'), time, x, meridiem;
for (prop in obj) {
if (obj.hasOwnProperty(prop)) {
x =+obj[prop].substr(0, 2);
if (x > 12) {
x = x % 12;
meridiem = "pm";
} else {
meridiem = "am";
}
time = x + ":00" + meridiem;
$output.append("- " + prop + " " + time + "
");
}
}