JavaScript toGMTString

The JavaScript toGMTString function converts the date and time into a string object using GMT. The basic syntax for this toGMTString Date Function is:

 Date.toGMTString()

toGMTString Example

We are using the toGMTString function to convert today’s date and time to a string object.

<!DOCTYPE html>
<html>
<head>
    <title> JS  </title>
</head>
<body>
    <h1> Example </h1>
<script>
  var dt = Date();  
  document.write("Date and Time : " + dt + "<br/>");

  var x = dt.toGMTString();
  document.write("After = " + x);
</script>
</body>
</html>
Example

Date and Time: Fri Nov 09 2018 11:59:15 GMT+0530 (Indian Standard Time)
After = Fri, 09 Nov 2018 06:29:15 GMT

Example 2

This JavaScript example converts the custom date and time into a string using GMT.

<!DOCTYPE html>
<html>
<head>
    <title> JavaScriptdatetoGMTStringFunction  </title>
</head>
<body>
    <h1> Example </h1>
<script>
  var dt = Date(2014, 11, 31, 02, 19, 5);
  document.write("Date and Time : " + dt + "<br/>");

  var x = dt.toGMTString();
  document.write("After toGMTString() = " + x);
</script>
</body>
</html>
toGMTString Example

About Suresh

Suresh is the founder of TutorialGateway and a freelance software developer. He specialized in Designing and Developing Windows and Web applications. The experience he gained in Programming and BI integration, and reporting tools translates into this blog. You can find him on Facebook or Twitter.