「JavaScript/Date」の版間の差分

削除された内容 追加された内容
Ef3 (トーク | 投稿記録)
→‎資料: Dateオブジェクトの各種メソッドの変換結果を調査しました。
Ef3 (トーク | 投稿記録)
→‎資料: 更新; +toLocaleString('ja-JP-u-ca-japanese', {era: 'long'})()
312 行
Dateオブジェクトの各種メソッドの変換結果を調査しました。
<source lang="js">
const a = [],date = new Date(2021,5,22), ua=navigator.userAgent;
a.push(`===Dateオブジェクトの変換結果: ${ua}===
{| class="wikitable"
|- align="left"
! メソッド !! 結果(型)`)
for (const p in Object.getOwnPropertyDescriptors(Date.prototype))
if (typeof Date.prototype[p] === "function" && /^to/.test(p))
a.push(`|-\n|! Date.prototype.${p}()\n| ${date[p]()}(${typeof date[p]()})`)
a.push(`|-\n!toLocaleString('ja-JP-u-ca-japanese', {era: 'long'})()\n| ${date.toLocaleString('ja-JP-u-ca-japanese', {era: 'long'})}`)
a.push`|}`
console.log(a.sort().join("\n"))
</source>
 
===Dateオブジェクトの変換結果: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.106124 Safari/537.36===
{| class="wikitable"
|- align="left"
! メソッド !! 結果(型)
|-
|! Date.prototype.toDateString()
| MonTue Jun 2122 2021(string)
|-
|! Date.prototype.toGMTString()
| Mon, 21 Jun 2021 0215:2600:5000 GMT(string)
|-
|! Date.prototype.toISOString()
| 2021-06-21T0221T15:2600:5000.762Z(string)000Z
|-
|! Date.prototype.toJSON()
| 2021-06-21T0221T15:2600:5000.762Z(string)000Z
|-
|! Date.prototype.toLocaleDateString()
| 2021/6/21(string)22
|-
|! Date.prototype.toLocaleString()
| 2021/6/2122 110:2600:50(string)00
|-
|! Date.prototype.toLocaleTimeString()
| 110:2600:50(string)00
|-
|! Date.prototype.toString()
| MonTue Jun 2122 2021 1100:2600:5000 GMT+0900 (日本標準時)(string)
|-
|! Date.prototype.toTimeString()
| 1100:2600:5000 GMT+0900 (日本標準時)(string)
|-
|! Date.prototype.toUTCString()
| Mon, 21 Jun 2021 0215:2600:5000 GMT(string)
|-
!toLocaleString('ja-JP-u-ca-japanese', {era: 'long'})()
| 令和3年6月22日 0:00:00
|}
 
===Dateオブジェクトの変換結果: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:89.0) Gecko/20100101 Firefox/89.0===
{| class="wikitable"
|- align="left"
! メソッド !! 結果(型)
|-
|! Date.prototype.toDateString()
| MonTue Jun 2122 2021(string)
|-
|! Date.prototype.toGMTString()
| Mon, 21 Jun 2021 0215:2700:0500 GMT(string)
|-
|! Date.prototype.toISOString()
| 2021-06-21T0221T15:2700:0500.337Z(string)000Z
|-
|! Date.prototype.toJSON()
| 2021-06-21T0221T15:2700:0500.337Z(string)000Z
|-
|! Date.prototype.toLocaleDateString()
| 2021/6/21(string)22
|-
|! Date.prototype.toLocaleString()
| 2021/6/2122 110:2700:05(string)00
|-
|! Date.prototype.toLocaleTimeString()
| 110:2700:05(string)00
|-
|! Date.prototype.toString()
| MonTue Jun 2122 2021 1100:2700:0500 GMT+0900 (日本標準時)(string)
|-
|! Date.prototype.toTimeString()
| 1100:2700:0500 GMT+0900 (日本標準時)(string)
|-
|! Date.prototype.toUTCString()
| Mon, 21 Jun 2021 0215:2700:0500 GMT(string)
|} -
!toLocaleString('ja-JP-u-ca-japanese', {era: 'long'})()
| 令和3年6月22日 0:00:00
|}
 
===Dateオブジェクトの変換結果: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.114 Safari/537.36 Edg/91.0.864.5459===
{| class="wikitable"
|- align="left"
! メソッド !! 結果(型)
|-
|! Date.prototype.toDateString()
| MonTue Jun 2122 2021(string)
|-
|! Date.prototype.toGMTString()
| Mon, 21 Jun 2021 0215:2700:2100 GMT(string)
|-
|! Date.prototype.toISOString()
| 2021-06-21T0221T15:2700:2100.136Z(string)000Z
|-
|! Date.prototype.toJSON()
| 2021-06-21T0221T15:2700:2100.136Z(string)000Z
|-
|! Date.prototype.toLocaleDateString()
| 2021/6/21(string)22
|-
|! Date.prototype.toLocaleString()
| 2021/6/2122 110:2700:21(string)00
|-
|! Date.prototype.toLocaleTimeString()
| 110:2700:21(string)00
|-
|! Date.prototype.toString()
| MonTue Jun 2122 2021 1100:2700:2100 GMT+0900 (日本標準時)(string)
|-
|! Date.prototype.toTimeString()
| 1100:2700:2100 GMT+0900 (日本標準時)(string)
|-
|! Date.prototype.toUTCString()
| Mon, 21 Jun 2021 0215:2700:2100 GMT(string)
|-
!toLocaleString('ja-JP-u-ca-japanese', {era: 'long'})()
| 令和3年6月22日 0:00:00
|}
 
 
== 脚注 ==