blob: b55d059b2b3c3a317ae328da27cad91cb4cc3d00 (
plain)
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
---
title: Date.prototype.toDateString()
slug: Web/JavaScript/Reference/Global_Objects/Date/toDateString
tags:
- Date
- JavaScript
- Method
- Prototype
- Reference
translation_of: Web/JavaScript/Reference/Global_Objects/Date/toDateString
---
<div>{{JSRef}}</div>
<p><strong><code>toDateString()</code></strong> メソッドは、 {{jsxref("Date")}} オブジェクトの日付部分を英語の次の書式で空白区切りで返します。</p>
<ol>
<li>曜日名の最初の3文字</li>
<li>月名の最初の3文字</li>
<li>2桁の日、必要であれば左に0埋め</li>
<li>4桁 (以上) の年、必要であれば左に0埋め</li>
</ol>
<p>例 "Thu Jan 01 1970".</p>
<div>{{EmbedInteractiveExample("pages/js/date-todatestring.html")}}</div>
<div class="hidden">このデモのソースファイルは GitHub リポジトリに格納されています。デモプロジェクトに協力したい場合は、 <a href="https://github.com/mdn/interactive-examples">https://github.com/mdn/interactive-examples</a> をクローンしてプルリクエストを送信してください。</div>
<h2 id="Syntax" name="Syntax">構文</h2>
<pre class="syntaxbox notranslate"><var>dateObj</var>.toDateString()</pre>
<h3 id="Return_value" name="Return_value">返値</h3>
<p>与えられた {{jsxref("Date")}} オブジェクトの「日付」部を表す文字列を人間が読める英語の表記で返します。</p>
<h2 id="Description" name="Description">解説</h2>
<p>{{jsxref("Date")}} インスタンスは、特定の時点を参照します。{{jsxref("Date.prototype.toString()", "toString()")}} を呼び出すと、人間が読める英語の表記で日付を返します。<a href="/ja/docs/Mozilla/Projects/SpiderMonkey">SpiderMonkey</a> では、この文字列は「日付」部 (日、月、年) と続く「時刻」部 (時、分、秒、タイムゾーン) からなります。時々、時刻の文字列を得たいことがあるでしょう。そのような場合は {{jsxref("Date.prototype.toTimeString()", "toTimeString()")}} メソッドが使えます。</p>
<p><a href="/ja/docs/Web/JavaScript/Language_Resources">ECMA-262</a> に従って実装されたエンジンは、{{jsxref("Date")}} オブジェクトに対して {{jsxref("Date.prototype.toString()", "toString()")}} メソッドから得られる文字列と異なることがあるため、<code>toDateString()</code> メソッドは特に役立ちます。その文字列の表記は実装依存であり、単純に文字列を切り出す方法では、複数のエンジンで一貫した結果を得られない可能性があります。</p>
<h2 id="Examples" name="Examples">例</h2>
<h3 id="A_basic_usage_of_toDateString" name="A_basic_usage_of_toDateString">toDateString() の基本的な使い方</h3>
<pre class="brush: js notranslate">var d = new Date(1993, 5, 28, 14, 39, 7);
console.log(d.toString()); // logs Mon Jun 28 1993 14:39:07 GMT-0600 (PDT)
console.log(d.toDateString()); // logs Mon Jun 28 1993
</pre>
<div class="note">
<p><strong>注:</strong> {{jsxref("Date")}} の引数として使用する場合、月は 0 から始まります(よって、 0 は 1 月に、 11 は 12 月 に対応します)。</p>
</div>
<h2 id="Specifications" name="Specifications">仕様書</h2>
<table class="standard-table">
<thead>
<tr>
<th scope="col">仕様書</th>
</tr>
</thead>
<tbody>
<tr>
<td>{{SpecName('ESDraft', '#sec-date.prototype.todatestring', 'Date.prototype.toDateString')}}</td>
</tr>
</tbody>
</table>
<h2 id="Browser_compatibility" name="Browser_compatibility">ブラウザーの互換性</h2>
<p>{{Compat("javascript.builtins.Date.toDateString")}}</p>
<h2 id="See_also" name="See_also">関連情報</h2>
<ul>
<li>{{jsxref("Date.prototype.toLocaleDateString()")}}</li>
<li>{{jsxref("Date.prototype.toTimeString()")}}</li>
<li>{{jsxref("Date.prototype.toString()")}}</li>
</ul>
|