Convert Time to GMT/Get GMT Offset
by salman
HTML
<p>Input</p>
<input type="text" name="time" id="time" value="07/21/2011 17:00">
<p>GMT Value</p>
<input type="text" name="gmtime" id="gmtime" readonly>
<p>GMT Offset (hours)</p>
<input type="text" name="offset" id="offset" readonly>
CSS
p {
font-family: monospace;
}
input {
font-family: monospace;
width: 300px;
}
JavaScript
document.getElementById("time").onchange = function() {
var d = new Date(this.value);
if (isNaN(d) == false) {
document.getElementById("gmtime").value = d.toUTCString();
}
}
document.getElementById("time").onchange();
document.getElementById("offset").value = (new Date()).getTimezoneOffset() / 60;