Friday, October 24, 2025
HomeLanguagesJavascriptJavaScript Date toGMTString() Method

JavaScript Date toGMTString() Method

The date.toGMTString() method is used to convert the given date object’s contents into a string according to the Greenwich Mean Time GMT. The date object is created using the date() constructor.

Note: This method has been deprecated and has been replaced by the toUTCString() method.

Syntax:

dateObj.toGMTString()

Parameters: This method does not accept any parameter. It is just used along with a Date object created using the Date() constructor whose contents are converted into a string. 

Return Values: It returns the converted string according to the Greenwich Mean Time GMT.

The below examples show the use of the Date toGMTString() method.

Example 1: In this example, we will convert a given time and date to GMT.

Javascript




<script>
    // Here a date has been assigned
    // while creating Date object
    var dateobj = new Date('October 15, 1996 05:35:32');
     
    // Contents of above date object is converted
    // into a string using toGMTString() method.
    var B = dateobj.toGMTString();
     
    // Printing the converted string.
    console.log(B);
</script>


Output:

Tue, 15 Oct 1996 00:05:32 GMT

Example 2: Here nothing is passed as a parameter while creating the date object but the toGMTString() method returns the current day, month, date, year, and time.

Javascript




<script type="text/javascript">
    var dt = new Date();
    console.log( "Formatted Date : " + dt.toGMTString() );
</script>


Output:

Formatted Date : Mon, 09 Jan 2023 05:54:54 GMT

We have a complete list of Javascript Date Objects, to check those please go through this Javascript Date Object Complete reference article.

We have a Cheat Sheet on Javascript where we covered all the important topics of Javascript to check those please go through Javascript Cheat Sheet-A Basic guide to JavaScript.

RELATED ARTICLES

Most Popular

Dominic
32361 POSTS0 COMMENTS
Milvus
88 POSTS0 COMMENTS
Nango Kala
6728 POSTS0 COMMENTS
Nicole Veronica
11892 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11954 POSTS0 COMMENTS
Shaida Kate Naidoo
6852 POSTS0 COMMENTS
Ted Musemwa
7113 POSTS0 COMMENTS
Thapelo Manthata
6805 POSTS0 COMMENTS
Umr Jansen
6801 POSTS0 COMMENTS