How to convert a JavaScript date to UTC?

 

A Javascript date can be converted to UTC using the functions present in the Javascript Date object.
The toUTCString() method is used to convert a Date object to a UTC string.
The toGMTString() function returns a string that represents a date based on the GMT (UT) time zone.

By default, JavaScript uses the browser's time zone and displays the date as a full-text string:

 

 var d = new Date();
 var n = d.toUTCString();

Tags:

Share:

Related posts