Jump to content

Gettimezonemodifier()


Renegade605

Recommended Posts

Hello, I'm trying to build a script that will display a list of Timezones (only 4 to choose from) and select the one your computer is set to. Since there's only 4, if your computer has none of them, it will choose CST. This is the code I have so far:

<form name="reportform" method="post" action="power.php"><!-- Irrelevant Form Fields --><select name="date[TimezoneModifier]" size="1">	<option value="+2">PST (GMT - 8:00)</option>	<option value="+1">MT (GMT - 7:00)</option>	<option value="0">CST (GMT - 6:00)</option>	<option value="-1">EST (GMT - 5:00)</option></select><script type="text/javascript">	var d = new Date();	alert('org = ' +d.getTimezoneOffset() +'\ndiv = ' +(d.getTimezoneOffset()/60));	var tz = (d.getTimezoneOffset()/60)-6; //The -6 modifies the values so they will match the values of the options (-1 through +2)	alert('tz = ' +tz);	//This is the loop I talk about below.	var sels = document.reportform.getElementsByTagName('select');	for (i = 0; i < sels.length; i++)	{		if (sels[i].name == "date[TimezoneModifier]")			{ var ops = sels[i].getElementsByTagName('option'); }	}	//End of stupid loop.	for (i = 0; i < ops.length; i++)	{		if ((tz >= -1) && (tz <= +2))		{			var val = Number(ops[i].value);			alert('(' +i +') ' +val +' == ' +tz +' ?');			if (val == tz) { ops[i].selected = 'selected'; }		}		else { if (ops[i].value == "0") { ops[i].selected = 'selected'; } }	}</script><!-- More Irrelevant Form Fields --></form>

For some reason that I can't explain, the getTimezoneModifier() EDIT: getTimezoneOffset() method is always returning 360, regardless of the timezone my computer is set to. How can I fix this?Also, I have this long and stupid for loop set to find the select list I'm looking for because it's name has [ and ] in it. When I tried finding it normally ("document.reportform.date[TimezoneModifier]") JS returned an error. I therefore made the for loop you see now. I know there has to be a better way to do that, so what is it?

Link to comment
Share on other sites

For some reason that I can't explain, the getTimezoneModifier() method is always returning 360, regardless of the timezone my computer is set to. How can I fix this?
I'm not seeing a getTimezoneModifier method, where are you using that?
When I tried finding it normally ("document.reportform.date[TimezoneModifier]") JS returned an error.
That's not really the "normal" way, that's the "old" way. Give the element an ID and use document.getElementById to get a reference to it.
Link to comment
Share on other sites

I believe that changing the time zone actually requires a reboot before the Javascript date object sees the changes, on Windows anyway. See if that's the issue, otherwise it looks like it's returning an offset of 6 hours.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...