With this script
getFormattedTime = function (fourDigitTime){
var hours24 = parseInt(fourDigitTime.substring(0,2));
var hours = ((hours24 + 11) % 12) + 1;
var amPm = hours24 > 11 ? 'pm' : 'am';
var minutes = fourDigitTime.substring(2);
return hours + ':' + minutes + amPm;
};
I can change 4 digit time to normal clock time (there is a problem with 0930 though..)
And with this
$("body").html($("body").html().replace(/1135/g,'11:35am'));
To replace any occurange of 1135 in my page.
However, in my page, I have a list of time in tables. I need to convert them e.g.
Class starts at 1700, please be there by 1630 and sign in by 1645.
It should translate into
Class starts at 05:00pm, please be there by 04:30pm and sign in by 04:45pm.
Assuming the only digits displayed in the text are the times you can use:
DEMO : http://jsfiddle.net/q6HC9/1
EDIT: Wrapping times in a tag would greatly simplify situation. Wrap all military times in a span with a common class and then use the
html()method