forked from technojam/world-clock
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
43 lines (31 loc) · 1.08 KB
/
main.js
File metadata and controls
43 lines (31 loc) · 1.08 KB
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
function showTime(){
d = new Date(); //Getting the local date object
utc = d.getTime() + (d.getTimezoneOffset() * 60000); //converting the time to gmt and in miliseconds for easier conversion of time for different countries
checkDropdown = document.getElementById("list").value; // getting the value of the selected country
var session = 'AM';
if(checkDropdown == 'india'){
nd = new Date(utc + (3600000*5.5)); // create new object of the date according to chosen country
}
else if(checkDropdown == 'california'){
nd = new Date(utc + (3600000*(-7)));
}
else if(checkDropdown == 'newYork'){
nd = new Date(utc + (3600000*(-4)));
}
// Changed the timming in 12 hours format
var res = nd.toLocaleString()
res = res.split(" ");
var ans = res[1].split(":");
if(ans[0]>12){
var t = parseInt(ans[0]) -12;
ans[0] = t.toString();
session = 'PM';
}
if(ans[0]==0){
ans[0] = '12';
}
res[1] = ans.join(":");
document.getElementById("clock").innerHTML = res[1]+" "+session;
setTimeout(showTime,1000);
}
showTime();