Your function converts "0:23" into "11:00 PM".
It'll also convert "0:45" into "00:00AM" (and "0:23" into "11:00PM").
No, I wouldn't. Leaving out the leading zero is pretty common where I'm from.
So noon is "12 in the morning", which is an hour after "11 in the morning"; and midnight is "12 in the evening", which is an hour after "11 in the evening".
† That is, you follow 11:00 PM with 12:00 AM, and you don't actually refer to "AM" or "PM". Both of those are normal US practice. You are different in the use of 24-hour formats in writing, but that has no bearing on the question of whether the hour following 11 PM is 12 AM; you just assured me that that's true in both countries.
// Preserve 2400h time by changing leading zeros to 24.
time = time.replace( /^0*[0:]/, '24' );That converts "0800" into "00:00AM".
time = time.replace( /^0*(0:)+/, '24' );