How to Convert a JavaScript Date to UTC

Assume, the user is in a timezone quite different from UTC and the date range should be converted to UTC.

This can be done by using JavaScript Date object. To convert a JavaScript date to UTC standard, you should use the toISOString method:

Javascript convert a date to UTC standard
const event = new Date('22 April 2020 12:22 UTC'); console.log(event.toString()); console.log(event.toISOString());
The toISOString() method returns a string that represents the given date in the ISO 8601 format according to universal time.

The toISOString() method returns a string in extended ISO format (ISO 8601). The timezone is zero UTC offset as indicated by the suffix "Z". It does not take any parameter and only used along with a Date object.

Date Object

JavaScript Date object represents a single instance in time in a platform-independent format. It contains a number that represents milliseconds since January 1, 1970, UTC. There are a number of methods that obtain a date in various formats, as well as to perform time zone conversions. There are also functions that output the date and time in UTC (Coordinated Universal Time), the global standard time defined by the World Time Standard.