How do you convert a JavaScript date to UTC?

JavascriptWeb DevelopmentFront End Technology

To convert a JavaScript date to UTC, use the getUTCDate() method. JavaScript date getUTCDate() method returns the day of the month in the specified date according to universal time. The value returned by getUTCDate is an integer between 1 and 31.

You can try to run the following code to convert a date to UTC −

Example

Live Demo

<html>
   <head>
      <title>JavaScript getUTCDate Method</title>
   </head>
   
   <body>
      <script>
         var dt = new Date( "December 31, 2017 23:15:20" );
         document.write("getUTCDate() : " + dt.getUTCDate() );
      </script>
   </body>
   
</html>

Output

getUTCDate() : 31
raja
Published on 13-Feb-2018 13:03:27
Advertisements