JavaScript toGMTString method
toGMTString() method of JavaScript is used to convert any date into the string according to GMT( Greenwich Mean Time ) and returns the converted string.
Syntax :
| date_object.toGMTString(); |
Where date_object is any date object reference which is to be converted into string format according to the GMT.
To understand the use of toGMTString() method in a better way let's go with a simple example. In this example we have converted current date to the string format according to GMT.
Description of code :
In this example code we have created a button which calls the function "convertToGMTString()" on the click event, which is defined in the <script></script> tags. It calls the toGMTString() method by the current date object and converted date is shown in an alert message. Here is the full example code as follows :
<html>
<head>
<title>toGMTString() method </title>
<script language="JavaScript">
function convertToGMTString()
{
alert(new Date().toGMTString());
}
</script>
</head>
<body>
<div style="background: #ff9900; width:'100%';"
align="center">
<font color="#0000ff" size="12pt">
<b>toGMTString() Example</b>
</font>
</div>
<center>
<p>
Click on the following button to show date into
GMT string
</p>
<input type="button" value="Convert current date
to GMT String" onClick="return convertToGMTString();"/>
</center>
</body>
</html>
|
Output :
Click on the button "Convert current date to GMT String"

As you can see from the above output that it shows the converted current date in an alert message box.
Tutorials
- Java 26 (JDK 26) Features with examples
- Top 10 Reasons to Learn Java in 2026
- JDK 26 Tutorial
- Java Certification Roadmap 2026: Which Oracle Certs Matter
- Install JDK 26: A Complete Beginner's Guide (2026)
- What Is Java? A Complete, Up-to-Date Guide for 2026
- Java 26 HTTP3 tutorial - HTTP 3 support in JDK 26 - How to use HTTP/3 in Java 26 application?
- JDK 28 Preview: Value Objects, Shenandoah GC & JSON API
- Java Tutorials


