JavaScript toGMTString method

This page discusses - JavaScript toGMTString method

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 :


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 :

<title>toGMTString() method </title>
 <script language="JavaScript">
  function convertToGMTString()
    alert(new Date().toGMTString());
<div style="background: #ff9900; width:'100%';"
  <font color="#0000ff" size="12pt">
	<b>toGMTString() Example</b>
       Click on the following button to show date into
               GMT string
       <input type="button" value="Convert current date 
    to GMT String" onClick="return convertToGMTString();"/>

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.

Download Source Code


Share on Google+Share on Google+

JavaScript toGMTString method

Posted on: April 18, 2011 If you enjoyed this post then why not add us on Google+? Add us to your Circles



Discuss: JavaScript toGMTString method  

Post your Comment

Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image