JavaScript Tutorial/Date/getTimezoneOffset — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
|
(нет различий)
|
Текущая версия на 08:25, 26 мая 2010
Date().getTimezoneOffset()
The getTimezoneOffset() method returns the difference between the time zones of local time and Greenwich Mean Time (GMT).
This difference is returned as an integer.
Although this is a method of a Date object, the actual date and time associated with the date is irrelevant because the time zone difference is based on the environment settings.
<html>
<head>
<title>Determine Time Zone</title>
</head>
<body>
<script language="JavaScript" type="text/javascript">
<!--
var current_date = new Date();
var current_timezone = current_date.getTimezoneOffset();
document.write("Your time zone is " + current_timezone + " minutes from GMT");
//-->
</script>
</body>
</html>
Display the timezone offsets for two different dates
<html>
<script language="JavaScript">
<!--
//Create 2 very different date objects
aDate1 = new Date(1990,1,1,0,0,0,0);
aDate2 = new Date(1994,2,13,8,24,45,300);
//
document.write("The timezone offset of aDate1 is ");
document.write(aDate1.getTimezoneOffset()," minutes.<br>");
document.write("The timezone offset of aDate2 is "
document.write(aDate2.getTimezoneOffset()," minutes.");
-->
</script>
</html>