forked from akkashsri/JavaScript-Clock
-
Notifications
You must be signed in to change notification settings - Fork 0
/
timezone_converter.html
88 lines (69 loc) · 2.15 KB
/
timezone_converter.html
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Timezone Converter</title>
</head>
<body onload="updateTimeZone()">
<div id="ConversionResultsDIV"></div>
<form name="form1">
<select size="5" name="lstCity" onchange="updateTimeZone();">
<option value="60" selected>Berlin
<option value="330">Bombay
<option value="0">London
<option value="180">Moscow
<option value="-300">New York (EST)
<option value="60">Paris
<option value="-480">San Francisco (PST)
<option value="600">Sydney
</select>
</form>
</body>
<script type="text/javascript">
var timeDiff;
var selectedCity;
var daylightSavingsAdjust = 0;
function updateTimeZone(){
var lstCity = document.form1.lstCity;
timeDiff = lstCity.options[lstCity.selectedIndex].value;
selectedCity = lstCity.options[lstCity.selectedIndex].text;
updateTime();
}
function getTimeString(dateObject){
var timeString;
var hours = dateObject.getHours();
if(hours < 10){
hours = "0" + hours;
}
var minutes = dateObject.getMinutes();
if(minutes<10){
minutes = "0" + minutes;
}
var seconds = dateObject.getSeconds();
if(seconds<10){
seconds ="0" + seconds;
}
timeString = hours + ":" + minutes + ":" + seconds;
return timeString;
}
function updateTime(){
var nowTime = new Date();
var resultsText = "<p>Indian Time is " + getTimeString(nowTime) + "</p>";
nowTime.setMinutes(nowTime.getMinutes() + nowTime.getTimezoneOffset() + parseInt(timeDiff) + daylightSavingsAdjust);
resultsText += "<p>" + selectedCity + " time is "+ getTimeString(nowTime)
+ "</p>";
document.getElementById("ConversionResultsDIV").innerHTML = resultsText;
}
function chkDaylightSaving_onclick(){
if(document.form1.chkDaylightSaving.checked){
daylightSavingsAdjust = 60;
}
else{
daylightSavingsAdjust = 0;
}
updateTime();
}
</script>
</html>