【发布时间】:2012-02-17 18:39:48
【问题描述】:
当我使用 UTC() 函数从纪元时间 (1 jan 1970) 获取总秒数时。但是再次使用“new Date(milliseconds)”构造函数将相同的秒数转换为 Date 并没有给出 UTC date 。 (按照 UTC 时间的秒数)。
我在印度 (GMT +05:30 ) 以下是我的 Html 文件
<html>
<head>
<title>GMT Calculator</title>
<script type="text/javascript">
function calcGMT(form) {
var dt = new Date();
var sc =Date.UTC(dt.getFullYear(),dt.getMonth(),dt.getDate(),dt.getHours(),dt.getMinutes(),dt.getSeconds()) ;
alert("date is "+new Date(sc));
}
window.onload = calcGMT;
</script>
</head>
<body>
</body>
</html>
我还发现它给出的一件事是“日期是 2012 年 1 月 25 日星期三 01:02:17 GMT+0530(印度标准时间)”,时间为 19:32,比当前时间早 5:30 .我不明白发生了什么。它应该根据函数 "toUTCString()" Tue, 24 Jan 2012 14:02:17 GMT 给出 UTC 日期字符串的时间,比当前时间少 5:30。
提前致谢!!
【问题讨论】:
标签: javascript html