In this article, I’ll show you how to convert a date to UTC using JavaScript with 2 methods: toUTCString()
and getTimezoneOffset()
. Learn more about it with the explanation and examples below.
What is UTC?
UTC stands for the English word “Universal Time Coordinated” and the French word “Temps Universel Coordonné”. Time UTC stands for Universal Time Coordinated, chosen by International Metrology (BIPM) as the infrastructure for locating time.
UTC was born based on the old standard time, GMT – Universal time.
The world is divided into however short 24 time periods. We sometimes designate their times as ½, according to the locator address.
Create current time using the Date() method
We can use the Date()
method in Javascript to get the current time in your area. Date in JavaScript is an built-in object that helps you to store date (day, month, year), time (hour, minute, second) , and manage date/time.
To initialize a Date object in JavaScript, simply call the new Date()
constructor with one of the following parameters.
Syntax:
new Date()
Parameters: None.
Code:
var now = new Date(); console.log(now)
Output:
Tue Sep 20 2022 00:04:29 GMT+0700 (Indochina Time)
The above example uses the Date()
method to get the current time value and assign it to the now
variable. We then print that value to the console.
Convert a date to UTC using JavaScript
Using toUTCString() method
The JavaScript Date toUTCString()
method converts a date into a string using the Universal Time Convention. You can use toUTCString()
method to convert a date to a UTC string.
Syntax:
toUTCString()
Parameters: None.
Example:
var now = new Date(); var utc = now.toUTCString(); console.log(utc);
Output:
Mon, 19 Sep 2022 17:19:21 GMT
So after you use the toUTCString()
method with the current time, it converts a date to a string, using the universal time zone.
Using getTimezoneOffset() method
In this example, we use the getTimezoneOffset()
method to convert a date to UTC. This method will return the time difference between the current system time zone and UTC in minutes.
Syntax:
getTimezoneOffset()
Parameters: None.
Example:
var now = new Date(); var utc = new Date(now.getTime() + now.getTimezoneOffset() * 60000); console.log(utc);
Output:
Mon Sep 19 2022 17:19:21 GMT+0700 (Indochina Time)
The utc
variable is calculated by using the current time plus the user’s current time zone to get the current UTC.
Summary
To summarize, this article shows you two ways to convert a date to UTC using JavaScript. You can use both of them to convert a date to the UTC effectly. Thank you for your reading!
Maybe you are interested:
- Get the month name from a date in javascript
- Convert seconds to HH:MM:SS in JavaScript
- Add Seconds to a Date using JavaScript

Hi, my name’s Nathaniel Kirk. I’m interested in learning and sharing knowledge about programming languages. My strengths are C, C++, Python, HTML, CSS, Javascript, and Reactjs. If you have difficulty with them, don’t worry. I’m here to support you.
Name of the university: PTIT
Major: IT
Programming Languages: C, C++, Python, HTML, CSS, Javascript, Reactjs