JavaScript toGMTString

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

 Date.toGMTString()

JavaScript toGMTString Function Example

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

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

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

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

JavaScript to GMT String Function Example 2

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

<!DOCTYPE html>
<html>
<head>
    <title> JavaScript date toGMTString Function  </title>
</head>
<body>
    <h1> JavaScript toGMTString 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>
JavaScript toGMTString Function 2