Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Timezone selection

<script language="JavaScript">
function calcTime(offset) 
{
    d = new Date();
    utc = d.getTime() + (d.getTimezoneOffset() * 60000);
    nd = new Date(utc + (3600000*offset));
    return "The local time is " + nd.toLocaleString();  }      
alert(calcTime('-8'));
alert(calcTime('-7'));
alert(calcTime('-6'));
alert(calcTime('-5'));
</script> 

'In this I have 4 alerts to show timezone's time and date.and at every load of page it shows all 4 alerts... but i want to show the value of alerts in textbox with dropdown selection. i have 4 drop down values Pacific, Mountain, Central And Eastern timezone. I want to show result value in textbox on dropdown selection. Please help to solve this problem. '

like image 497
Ghost Avatar asked May 02 '26 05:05

Ghost


1 Answers

Hope this is what you ask for:

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

Update

Javascript:

<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>

HTML:

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

like image 104
arunrc Avatar answered May 04 '26 19:05

arunrc



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!