Javascript: Get client's TimeZone

How to know client's time and time zone? The simplest way that can do this is using the javascript.

<script type="text/javascript">
function displayTime()
{
var localTime = new Date();
//this one will give you the GMT offset
var timezone = localTime.getTimezoneOffset()/60 * (-1);
var div = document.getElementById("div1");
div.innerText = "GMT" + timezone;
}
</script>
Or simply use
<script type="text/javascript">
function displayTime()
{
var div = document.getElementById("div1");
div.innerText = (new Date()).toString();
}
</script>

0 Comments:

Random Posts

Powered by Stuff-a-Blog