给出不同结果的日期Javascript函数

给出不同结果的日期Javascript函数,javascript,jquery,Javascript,Jquery,我将它运行到我的浏览器,得到不同的结果,当用python将它转换为日期时,我也得到了两个不同的日期。为什么? 在这里输入代码 <!DOCTYPE html> <html> <body> <p>Click the button to display the numbers of milliseconds between a specified date and midnight January 1, 1970.</p> <butto

我将它运行到我的浏览器,得到不同的结果,当用python将它转换为日期时,我也得到了两个不同的日期。为什么?

在这里输入代码

<!DOCTYPE html>
<html>
<body>
<p>Click the button to display the numbers of milliseconds between a specified date and midnight January 1, 1970.</p>
<button onclick="myFunction()">Try it</button>
<p> UTC </p>
<p id="demo"></p>
<p> get Time method</p>
<p id="UTC"></p>
<script>
function myFunction() {
var d = Date.UTC(2016, 03, 10);
var dt=  new Date(2016, 03, 10);
document.getElementById("demo").innerHTML = d;
document.getElementById("UTC").innerHTML =dt.getTime(); 
}
</script>
</body>
</html>

单击按钮可显示指定日期与1970年1月1日午夜之间的毫秒数

试试看 UTC

获取时间方法

函数myFunction(){ var d=UTC日期(2016年3月10日); var dt=新日期(2016年3月10日); document.getElementById(“demo”).innerHTML=d; document.getElementById(“UTC”).innerHTML=dt.getTime(); }
UTC!==本地时间但当我将其转换为python datetime时,我得到了这个打印日期时间。fromtimestamp(1460246400000/1000.0):-2016-04-10 05:30:00打印日期时间。fromtimestamp(1460226600000/1000.0):-2016-04-10 00:00:00不同的小时/分钟是UTC和本地时区之间的差异。“错误”月份是因为
日期(y,m,d)
中的月份参数以零为基础<代码>0=一月,1=二月,…谢谢@Andreas的建议。现在对我来说很好。