如何使用通用时间约定将日期转换为字符串?

若要使用通用时间约定将日期转换为字符串,请使用toUTCString()方法。它使用通用时间约定将转换后的日期返回为字符串。

示例

您可以尝试运行以下代码,以了解如何使用UTC将日期转换为字符串-

<html>
   <head>
      <title>JavaScript toUTCString Method</title>
   </head>
   <body>
      <script>
         var dateobject = new Date(2018, 0, 15, 14, 39, 7);
         document.write( dateobject.toUTCString() );
      </script>
   </body>
</html>