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 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>