1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
---
title: Date.prototype.toGMTString()
slug: Web/JavaScript/Reference/Global_Objects/Date/toGMTString
translation_of: Web/JavaScript/Reference/Global_Objects/Date/toGMTString
---
<div>{{JSRef("Global_Objects", "Date")}} {{ Deprecated_header() }}</div>
<p>The <code><strong>toGMTString()</strong></code> method converts a date to a string, using Internet GMT conventions. The exact format of the value returned by <code>toGMTString</code> varies according to the platform and browser, in general it should represent a human readable date string.</p>
<p><strong>Note</strong>: <code>toGMTString</code> is deprecated and should no longer be used, it's only there for backwards compatibility, use {{jsxref("Date.toUTCString", "toUTCString()")}} instead.</p>
<h2 id="Syntax" name="Syntax">Syntax</h2>
<pre class="syntaxbox"><var>dateObj</var>.toGMTString()</pre>
<h2 id="Examples" name="Examples">Examples</h2>
<h3 id="Example:_Using_toGMTString" name="Example:_Using_toGMTString">Example: Using <code>toGMTString</code></h3>
<p>In this example, the <code>toGMTString</code> method converts the date to GMT (UTC) using the operating system's time-zone offset and returns a string value that is similar to the following form. The exact format depends on the platform.</p>
<pre class="brush: js">var today = new Date();
var str = today.toGMTString(); // deprecated! use toUTCString()
console.log(str); // Mon, 18 Dec 1995 17:28:35 GMT
</pre>
<h2 id="Specifications">Specifications</h2>
<table class="standard-table">
<tbody>
<tr>
<th scope="col">Specification</th>
<th scope="col">Status</th>
<th scope="col">Comment</th>
</tr>
<tr>
<td>ECMAScript 1st Edition. Implemented in JavaScript 1.0</td>
<td>Standard</td>
<td>Initial definition, but already declared as deprecated.</td>
</tr>
<tr>
<td>{{SpecName('ES5.1', '#sec-B.2.6', 'Date.prototype.toGMTString')}}</td>
<td>{{Spec2('ES5.1')}}</td>
<td>Defined in the (informative) compatibility annex.</td>
</tr>
<tr>
<td>{{SpecName('ES6', '#sec-date.prototype.togmtstring', 'Date.prototype.toGMTString')}}</td>
<td>{{Spec2('ES6')}}</td>
<td>Defined in the (normative) annex for additional features for web browsers.</td>
</tr>
</tbody>
</table>
<h2 id="Browser_compatibility">Browser compatibility</h2>
<p class="hidden">The compatibility table in this page is generated from structured data. If you'd like to contribute to the data, please check out <a href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a> and send us a pull request.</p>
<p>{{Compat("javascript.builtins.Date.toGMTString")}}</p>
<h2 id="See_Also" name="See_Also">See also</h2>
<ul>
<li>{{jsxref("Date.prototype.toLocaleDateString()")}}</li>
<li>{{jsxref("Date.prototype.toTimeString()")}}</li>
<li>{{jsxref("Date.prototype.toUTCString()")}}</li>
</ul>
|