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
- Clear cookie example
- JavaScript getElementById innerHTML
- JavaScript getElementById Style
- Javascript Examples
- JavaScript add row dynamically to table
- New Page 1
- JavaScript Change link
- JavaScript Checkbox getElementById
- javascript clear textarea
- JavaScript Clock Timer
- JavaScript Cookies
- JavaScript Date Difference
- JavaScript duplicate string
- JavaScript Email Validation
- javascript focus input
- JavaScript get excel file data
- JavaScript getAttribute Href
- JavaScript getAttribute Style
- JavaScript getElementById div
- JavaScript getElementById Iframe
- JavaScript getElementById select
- JavaScript Hide Button
- JavaScript Hide Div
- JavaScript hide image
- JavaScript Hide Table Column
- JavaScript Hide Table Rows
- JavaScript Key Event
- JavaScript link
- JavaScript method location
- JavaScript move div
- JavaScript move file
- JavaScript move image
- JavaScript Navigate Back
- JavaScript navigate to page
- JavaScript Navigate to URL
- JavaScript indexOf substring
- JavaScript onkeypress event
- JavaScript Open file
- JavaScript Open link in new window
- JavaScript Open Modal Window


