JavaScript中解析日期的用途是什么?

解析 日期将为我们提供时间(以毫秒为单位)。Date.parse()用于解析 日期。此方法实际上返回提供的日期与1970年1月1日之间的毫秒数。开发人员以这种方式对其进行了编程,以获取从1970年1月1日到提供的日期的毫秒数。

示例1

在以下示例中,使用Date.parse()计算了2019年7月14日至1970年1月1日之间的毫秒数。

<html>
<body>
   <p>Date.parse() returns the number of milliseconds between
      july 14, 2019 and January 1, 1970 </p>
   <script>
      var time = Date.parse("july 14, 2019");
      document.write(time);
   </script>
</body>
</html>

输出结果

1563042600000

示例2

在下面的示例中,使用Date.parse()计算了1999年6月14日至1970年1月1日之间的毫秒数。

<html>
<body>
   <p>Date.parse() returns the number of milliseconds between
   the june 14, 1999 and January 1, 1970: </p>
   <script>
      var time = Date.parse("june 14, 1999");
      document.write(time);
   </script>
</body>
</html>

输出结果

929298600000