JavaScript Date getTime()方法 (JavaScript Date getTime() method)
getTime() method is a Date's class method and it is used to get the time in milliseconds from 1st January 1970.
getTime()方法是Date的类方法,用于获取从1970年1月1 日开始的时间(以毫秒为单位)。
It accepts nothing as the parameter and returns a total number of milliseconds from 1st January 1970 to till now.
它接受什么作为参数,并从1 日 1970年1月返回毫秒的总数至今。
Syntax:
句法:
var dt = new Date();
dt.getTime();
Examples:
例子:
Input:
var dt = new Date();
dt.getTime();
Output:
1551709453576
JavaScript code to get the time in milliseconds using getTime() method
JavaScript代码使用getTime()方法获取以毫秒为单位的时间
<html>
<head><title>JavaScipt Example</title></head>
<body>
<script>
var dt = new Date(); //Date constructor
var timeinMs = dt.getTime(); //getting time in milliseconds
//printing time
document.write("Current time is (in milliseconds): " + timeinMs);
</script>
</body>
</html>
Output
输出量
Current time is (in milliseconds): 1551709453576
翻译自: https://www.includehelp.com/code-snippets/date-getTime-method-with-example-in-javascript.aspx