Solved

calculate user's local time as certain GMT times are selected from a drop down box

Posted on 2004-10-09
4
241 Views
Last Modified: 2008-03-06
Hi experts,

I am looking for a way to calculate on-the-fly the user's local time as certain GMT times are selected from a drop down box as follows:

<select><option>0:00</option><option>0:30</option> etc </select>

As an input argument to the javascript function that would do this would be the zone offset calculated via  
      
var curDateTime = new Date()
var myVal = -curDateTime.getTimezoneOffset()/60

from an earlier script.  So as he selects different GMT times, his local time appears beside his choice and updates as he selects different GMT times.

thanks,
kesea
0
Comment
Question by:kesea
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 

Author Comment

by:kesea
ID: 12268333
Just to clarify, I don't need help with the math part - I would just output the hour selected + the zone offset followed by the minutes.  What I don't know how to do is output this result beside the drop box and have it change on-the-fly as different options are selected from the drop box.
0
 
LVL 15

Accepted Solution

by:
Colosseo earned 500 total points
ID: 12268400
Hi kesea

I have created an example webpage for you.

All you will have to do is add your math in to the function to complete it.

Right now it passes the option selected in the drop down to the javascript function and then displays the results to the page.

The function is also called in the onload of the body so that an initial value is generated for the local time but this is not required if you don't want it to do that.

<html>
<head>
</head>
<script language="javascript">

  // This function uses the passed GMT time to calculate the user's local time
  function calcLocalTime(GMT)
  {
    //Variable to hold the local time
    var localTime;

    // Set the local time to the passed GMT value as an example so code works just now
    //
    // This is where you would implement your code
    //
    localTime = GMT;

    // Output the users local time
    document.all.localTime.innerHTML = localTime;
  }

</script>
<body onload="calcLocalTime(document.all.selGMT.value);">

<select name="selGMT" onChange="calcLocalTime(this.value);">
  <option value="0:00">0:00</option>
  <option value="0:30">0:30</option>
</select>

The user's local time is: <span name="localTime" id="localTime"></span

</body>
</html>

Hope thats of use, any problems/questions then just let me know

Cheers

Scott

0
 

Author Comment

by:kesea
ID: 12268571
Just what I needed.  Thank-you very much.
0
 
LVL 15

Expert Comment

by:Colosseo
ID: 12268583
your very welcome and thanks for the grade

Cheers

Scott
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article, we'll look how to sort an Array in JavaScript, including the more advanced techniques of sorting a collection of records either ascending or descending on two or more fields. Basic Sorting of Arrays First, let's look at the …
In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

717 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question