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 −


Live Demo

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


getUTCDate() : 31
Published on 13-Feb-2018 08:33:27