Q:

JavaScript - Converting time from 12h into 24h format

I tried many methods, but I always end up without solution. What I need is a javascript code which can convert time from div.postedOn from 12h to 24h format.
div.postedTime example:
<div class="postedOn"><img src="http://assets7.thatsite.com/images/forums/post/reply.gif?v3" alt="">&nbsp;&nbsp;Posted on June 3, 2012 1:46 AM</div>

So, I need to convert '1:46 PM' to '01:46' without removing any contents from the <div>.

A:

If the format is always the same, then this will work fine:
out = in.replace(/(\d+):(\d+) ([AP])M/,function(m) {
    m[1] = m[1]%12;
    if( m[3] == "P") m[1] += 12;
    if( m[1] < 10) m[1] = "0"+m[1];
    return m[1]+":"+m[2];
});

A:

Similar to Kolink, adding another regex solution...
var str = "Posted on June 3, 2012 2:00 PM";
var regex = /([01]?\d)(:\d{2}) (AM|PM)/g;
var match = regex.exec(str);
str.replace(regex, (+match[1] + (match[3]=='AM'? 0 : 12)) + match[2] + match[3]);

