-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
52 lines (47 loc) · 1.66 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
$(document).ready(function() {
$("input[name=time]").clockpicker({
placement: 'bottom',
align: 'right',
autoclose: true,
default: 'now',
donetext: "done"
});
});
document.addEventListener('DOMContentLoaded', function() {
var timeInput = document.getElementById('time1');
timeInput.addEventListener('click', function() {
document.getElementsByTagName("html")[0].style.height = "500px";
});
timeInput.addEventListener('blur', function() {
document.getElementsByTagName("html")[0].style.height = "300px";
});
var convertButton = document.getElementById('converttime');
convertButton.addEventListener('click', function() {
convert_time();
});
});
function convert_time()
{
var textBoxValue = document.getElementById("time1").value;
var regex = /^([01]\d|2[0-3]):?([0-5]\d)$/;
document.getElementById("lbl").innerText = ' ';
if (regex.test(textBoxValue)) {
let first_part_time = textBoxValue.split(':')[0]
if (first_part_time > 12 && first_part_time < 24)
{
let final_time = first_part_time-12;
document.getElementById("lbl").innerText = final_time +":"+ textBoxValue.split(':')[1] + " " +'PM';
}
else{
if(textBoxValue.split(':')[0] != 00)
{
document.getElementById("lbl").innerText = first_part_time +":"+ textBoxValue.split(':')[1] + " " +'AM';
}else{
document.getElementById("lbl").innerText = 12 +":"+ textBoxValue.split(':')[1] + " " +'AM';
}
}
}else{
alert("Invalid Format")
document.getElementById("time1").value = ' ';
}
}