JavaScript getMilliseconds 函数

JavaScript getMilliseconds 函数是 Date 函数之一,它返回给定日期的毫秒数。

使用 get Milliseconds 返回当前日期和时间的总毫秒数。

<!DOCTYPE html>
<html>
<head>
    <title> JS </title>
</head>
<body>
    <h1> Example </h1>
<script>
  var dt = Date();  
  document.write("Date and Time : " + dt);
  document.write("Milliseconds : " + dt.getMilliseconds());
</script>
</body>
</html>
Example

Date and Time: Sun Nov 04 2018 16:08:08 GMT+0530 (Indian Standard Time)
Milliseconds : 650

在此 getMilliseconds 函数示例中,我们从自定义日期查找毫秒。

<!DOCTYPE html>
<html>
<head>
    <title> JavaScriptGetMillisecondsFunction </title>
</head>
<body>
    <h1> JavaScriptgetMillisecondsFunctionExample </h1>
<script>
  var dt = Date("December 22, 2016 10:19:45.314");
  document.write("Date and Time : " + dt);
  document.write("Milliseconds using getMilliseconds(): " + dt.getMilliseconds());
</script>
</body>
</html>
getMilliseconds Function Example

JavaScript 示例在没有(时间)的情况下从自定义日期返回毫秒。它返回 0 毫秒。

<!DOCTYPE html>
<html>
<head>
    <title> JS </title>
</head>
<body>
    <h1> Example </h1>
<script>
  var dt = Date("December 22, 1972");
  document.write("DateTime : " + dt);
  document.write("Milliseconds : " + dt.getMilliseconds());
</script>
</body>
</html>
Example

DateTime: Fri Dec 22 1972 00:00:00 GMT+0530 (Indian Standard Time)
Milliseconds : 0