Question

<script> function displayTime(){ var h = new Date().getHours(); var m = new Date().getMinutes() var s =...

<script>
function displayTime(){
var h = new Date().getHours();
var m = new Date().getMinutes()
var s = new Date().getSeconds()
var ha = h * (360/12) + (m*.5);
var ma = m * (360/60)
var sa = s * (360/60);

document.getElementById("sec").style.transform = 'translate(150px) rotate(' + sa + 'deg)'
document.getElementById("min").style.transform = 'translate(150px,20px) rotate(' + ma + 'deg)'
document.getElementById("hour").style.transform = 'translate(150px,50px) rotate(' + ha + 'deg)'
}
function start(){
displayTime();
setInterval("displayTime()", 1000);
}
</script>
</head>

<body onload='start()'>
<select name="DropDownTimezone" id="DropDownTimezone">
<option value="default">You are here</option>
<option value="-12.0">(GMT -12:00) Eniwetok, Kwajalein</option>
<option value="-11.0">(GMT -11:00) Midway Island, Samoa</option>
<option value="-10.0">(GMT -10:00) Hawaii</option>
<option value="-9.0">(GMT -9:00) Alaska</option> </select>

I have this html and java script code. This webpage gives user to select different timezone and displays that time in a analog clock. I just want to know how to use getTimezoneOffset() to make this dropdown menu functional. I would really appreciate if someone could help me. Thank you.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

The client’s timezone offset could be detected by using the Date object’s getTimezoneOffset() method.

The getTimezoneOffset() method returns the time difference between UTC time and local time, that is the time offset, in minutes. This offset is changed by dividing by 60 and negating the result.

below function will return the getTimeZone()

<input type="text" name="result" id="result" value="">

<select name="timezone" onChange="calcTime(this.value)">

<script language="JavaScript">
function calcTime(offset) 
{
    d = new Date();
    utc = d.getTime() + (d.getTimezoneOffset() * 60000);
    nd = new Date(utc + (3600000*offset));
    document.getElementById('result').value=nd.toLocaleString();
}      
</script>
Add a comment
Know the answer?
Add Answer to:
<script> function displayTime(){ var h = new Date().getHours(); var m = new Date().getMinutes() var s =...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Form Processing HTML One of the most ubiquitous uses of JavaScript is validating form data on...

    Form Processing HTML One of the most ubiquitous uses of JavaScript is validating form data on the client side before it is submitted to the server. It is done everywhere because it is fast and it gives you a great deal of flexibility in how you handle errors insofar as the GUI is concerned. Attached is an image of some code I wrote (so Blackboard can't mess it up). Some things to notice that will help you with the lab....

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT