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

htmljavascriptprogramming scripts

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

示例

您可以尝试运行以下代码来返回表示等效 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>

相关文章