如何返回表示等效Date对象来源的字符串?

要返回表示等效Date对象来源的字符串,请使用JavaScripttoSource()方法。此方法返回一个表示对象源代码的字符串。

示例

您可以尝试运行以下代码以返回表示等效Date对象来源的字符串-

<html>
   <head>
      <title>JavaScript toSource() Method</title>
   </head>
   <body>
      <script>
         var dt = new Date(2018, 0, 15, 14, 39, 7);
         document.write( "Formated Date : " + dt.toSource() );
      </script>
   </body>
</html>