This script code will help too convert Military Time To Civilian Time .
<script >
var timer_clk23;
function twodigits(input) {
input = input + "";
if (input.length == 1) {
return "0" + input;
}
return input;
}
function conv24to12clock(hours, ampm24) {
if ( ampm24 == "24" ) {
if (hours < 12) {
a_p = "AM";
} else {
a_p = "PM";
}
if (hours == 0) {
hours = 12;
}
if (hours > 12) {
hours = hours - 12;
}
hours = twodigits ( hours );
hours = hours + a_p;
} else {
if (hours == 12) {
hours = 0;
}
if (ampm24 == "pm") {
hours = parseInt(hours) + 12;
}
hours = twodigits ( hours );
}
return hours;
}
function timerTick() {
var d = new Date();
var curr_hour = d.getHours();
var curr_12hr = conv24to12clock(curr_hour, "24");
var curr_min = twodigits( d.getMinutes() );
var curr_sec = twodigits( d.getSeconds() );
curr_hour = twodigits(curr_hour);
var current_24hour = curr_hour + ":" + curr_min + ":" + curr_sec;
var current_12hour = curr_12hr.substring(0,2) + ":" + curr_min + ":" + curr_sec + " " + curr_12hr.substring(2);
var current_times = "";
current_times = <tr><td>Current time in 24-hour format</font></td>";
current_times += "\n<td> </td>\n";
current_times += "<td >Current time in 12-hour format</font></td></tr>";
current_times += "<tr> <td>" + current_24hour + "</font></td>";
current_times += "\n<td> </td>\n";
current_times += "<td>" + current_12hour + "</font></td></tr></table>";
document.getElementById('currenttime').innerHTML = current_times;
timer_clk23 = setTimeout( "timerTick()" , 1000)
}
function convert24to12(convtype) {
if ( convtype == "24" ) {
var hours12 = conv24to12clock(document.getElementById('hr24').value, "24");
document.getElementById('hr12').options[parseInt(hours12.substring(0,2),10)-1].selected = "selected";
if ( hours12.substring(2) == "AM" ) {
document.getElementById('ampmselector').options[0].selected = "selected";
} else {
document.getElementById('ampmselector').options[1].selected = "selected";
}
} else {
var hours24 = conv24to12clock(document.getElementById('hr12').value, document.getElementById('ampmselector').value);
document.getElementById('hr24').options[parseInt(hours24,10)].selected = "selected";
}
}
//-->
</script>
<script >
var timer_clk23;
function twodigits(input) {
input = input + "";
if (input.length == 1) {
return "0" + input;
}
return input;
}
function conv24to12clock(hours, ampm24) {
if ( ampm24 == "24" ) {
if (hours < 12) {
a_p = "AM";
} else {
a_p = "PM";
}
if (hours == 0) {
hours = 12;
}
if (hours > 12) {
hours = hours - 12;
}
hours = twodigits ( hours );
hours = hours + a_p;
} else {
if (hours == 12) {
hours = 0;
}
if (ampm24 == "pm") {
hours = parseInt(hours) + 12;
}
hours = twodigits ( hours );
}
return hours;
}
function timerTick() {
var d = new Date();
var curr_hour = d.getHours();
var curr_12hr = conv24to12clock(curr_hour, "24");
var curr_min = twodigits( d.getMinutes() );
var curr_sec = twodigits( d.getSeconds() );
curr_hour = twodigits(curr_hour);
var current_24hour = curr_hour + ":" + curr_min + ":" + curr_sec;
var current_12hour = curr_12hr.substring(0,2) + ":" + curr_min + ":" + curr_sec + " " + curr_12hr.substring(2);
var current_times = "";
current_times = <tr><td>Current time in 24-hour format</font></td>";
current_times += "\n<td> </td>\n";
current_times += "<td >Current time in 12-hour format</font></td></tr>";
current_times += "<tr> <td>" + current_24hour + "</font></td>";
current_times += "\n<td> </td>\n";
current_times += "<td>" + current_12hour + "</font></td></tr></table>";
document.getElementById('currenttime').innerHTML = current_times;
timer_clk23 = setTimeout( "timerTick()" , 1000)
}
function convert24to12(convtype) {
if ( convtype == "24" ) {
var hours12 = conv24to12clock(document.getElementById('hr24').value, "24");
document.getElementById('hr12').options[parseInt(hours12.substring(0,2),10)-1].selected = "selected";
if ( hours12.substring(2) == "AM" ) {
document.getElementById('ampmselector').options[0].selected = "selected";
} else {
document.getElementById('ampmselector').options[1].selected = "selected";
}
} else {
var hours24 = conv24to12clock(document.getElementById('hr12').value, document.getElementById('ampmselector').value);
document.getElementById('hr24').options[parseInt(hours24,10)].selected = "selected";
}
}
//-->
</script>