国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 語言 > JavaScript > 正文

js獲得當前時區夏令時發生和終止的時間代碼

2024-05-06 16:01:32
字體:
來源:轉載
供稿:網友
這篇文章主要介紹了js獲得當前時區夏令時發生和終止的時間代碼,需要的朋友可以參考下

復制代碼 代碼如下:


<!DOCTYPE html>
<html>
<head>
<title>DST Calculator</title>
<script type="text/javascript">

function DisplayDstSwitchDates()
{
var year = new Date().getYear();
if (year < 1000)
year += 1900;

var firstSwitch = 0;
var secondSwitch = 0;
var lastOffset = 99;

// Loop through every month of the current year
for (i = 0; i < 12; i++)
{
// Fetch the timezone value for the month
var newDate = new Date(Date.UTC(year, i, 0, 0, 0, 0, 0));
var tz = -1 * newDate.getTimezoneOffset() / 60;

// Capture when a timzezone change occurs
if (tz > lastOffset)
firstSwitch = i-1;
else if (tz < lastOffset)
secondSwitch = i-1;

lastOffset = tz;
}

// Go figure out date/time occurences a minute before
// a DST adjustment occurs
var secondDstDate = FindDstSwitchDate(year, secondSwitch);
var firstDstDate = FindDstSwitchDate(year, firstSwitch);

if (firstDstDate == null && secondDstDate == null)
return 'Daylight Savings is not observed in your timezone.';
else
return 'Last minute before DST change occurs in ' +
year + ': ' + firstDstDate + ' and ' + secondDstDate;
}

function FindDstSwitchDate(year, month)
{
// Set the starting date
var baseDate = new Date(Date.UTC(year, month, 0, 0, 0, 0, 0));
var changeDay = 0;
var changeMinute = -1;
var baseOffset = -1 * baseDate.getTimezoneOffset() / 60;
var dstDate;

// Loop to find the exact day a timezone adjust occurs
for (day = 0; day < 50; day++)
{
var tmpDate = new Date(Date.UTC(year, month, day, 0, 0, 0, 0));
var tmpOffset = -1 * tmpDate.getTimezoneOffset() / 60;

// Check if the timezone changed from one day to the next
if (tmpOffset != baseOffset)
{
var minutes = 0;
changeDay = day;

// Back-up one day and grap the offset
tmpDate = new Date(Date.UTC(year, month, day-1, 0, 0, 0, 0));
tmpOffset = -1 * tmpDate.getTimezoneOffset() / 60;

// Count the minutes until a timezone chnage occurs
while (changeMinute == -1)
{
tmpDate = new Date(Date.UTC(year, month, day-1, 0, minutes, 0, 0));
tmpOffset = -1 * tmpDate.getTimezoneOffset() / 60;

// Determine the exact minute a timezone change
// occurs
if (tmpOffset != baseOffset)
{
// Back-up a minute to get the date/time just
// before a timezone change occurs
tmpOffset = new Date(Date.UTC(year, month,
day-1, 0, minutes-1, 0, 0));
changeMinute = minutes;
break;
}
else
minutes++;
}

// Add a month (for display) since JavaScript counts
// months from 0 to 11
dstDate = tmpOffset.getMonth() + 1;

// Pad the month as needed
if (dstDate < 10) dstDate = "0" + dstDate;

// Add the day and year
dstDate += 'http://www.survivalescaperooms.com/' + tmpOffset.getDate() + 'http://www.survivalescaperooms.com/' + year + ' ';

// Capture the time stamp
tmpDate = new Date(Date.UTC(year, month,
day-1, 0, minutes-1, 0, 0));
dstDate += tmpDate.toTimeString().split(' ')[0];
return dstDate;
}
}
}

</script>
</head>
<body>
<script type="text/javascript">
document.write("Current date/time: " + new Date() + "<br />");
document.write(DisplayDstSwitchDates());
</script>
</body>
</html>

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表

圖片精選

主站蜘蛛池模板: 雷山县| 无为县| 九寨沟县| 黑龙江省| 阿勒泰市| 马鞍山市| 嘉义县| 大方县| 阿拉善右旗| 观塘区| 唐山市| 绥棱县| 宜兴市| 当涂县| 正阳县| 兰考县| 天门市| 浮梁县| 无为县| 中江县| 进贤县| 巴塘县| 建昌县| 遵义市| 张掖市| 邵阳市| 咸丰县| 社旗县| 中卫市| 霍城县| 盐边县| 格尔木市| 任丘市| 闸北区| 醴陵市| 乌鲁木齐县| 惠州市| 报价| 安溪县| 靖西县| 淳化县|