The JavaScript toGMTString function converts the date and time into a string object using Greenwich Mean Time (GMT).
The basic syntax for this toGMTString Date Function is:
Date.toGMTString()
NOTE: The toGMTString method is deprecated and replaced by the toUTCString() function.
Return Value: This method does not accept any parameters and returns the string representation of the given date and time according to the GMT.
JavaScript toGMTString example
In the following example, we use the toGMTString function to convert today’s date and time to a string object.
const dt = new Date();
console.log(dt);
let g = dt.toGMTString();
console.log(g);
Tue Jun 16 2026 18:07:19 GMT+0530 (India Standard Time)
Tue, 16 Jun 2026 12:37:19 GMT
Example 2: In this JavaScript example, we use the Date() constructor to parse a custom date. Next, the JavaScript toGMTString() method converts the custom date and time into a string using GMT.
const dt = new Date(2024, 11, 31, 2, 19, 5);
console.log(dt);
let g = dt.toGMTString();
console.log(g);
If you notice the output below, the toGMTString() method returns the previous date because the local system date is 5:30 hours ahead of GMT.
Tue Dec 31 2024 02:19:05 GMT+0530 (India Standard Time)
Mon, 30 Dec 2024 20:49:05 GMT
Example 3: Here, we use the toGMTString() method on a custom date without the time. By default, the JavaScript adds 00:00:00 to the GMT, and for the local system, it adds 5 hours and 30 minutes.
const dt = new Date("2025-01-01");
console.log(dt);
let g = dt.toGMTString();
console.log(g);
Wed Jan 01 2025 05:30:00 GMT+0530 (India Standard Time)
Wed, 01 Jan 2025 00:00:00 GMT