{"action":"created","comment":{"url":"https://api.github.com/repos/asciidwango/js-primer/pulls/comments/139401693","pull_request_review_id":63322864,"id":139401693,"diff_hunk":"@@ -0,0 +1,190 @@\n+---\n+author: laco\n+---\n+\n+# Date\n+\n+この章では、JavaScriptで日付や時刻を扱うための[Date][]について学びます。\n+\n+## Dateオブジェクト\n+\n+`Date`オブジェクトは`String`や`Array`などと同じく、ビルトインのグローバルオブジェクトです。\n+そのため、スクリプト中のどこからでも呼び出して使えます。\n+\n+`Date`オブジェクトをインスタンス化することで、ある特定の時刻を表すオブジェクトが得られます。\n+`Date`における「時刻」は、UTC（協定世界時）の1970年1月1日0時0分0秒を基準とした相対的なミリ秒として保持されます。\n+このミリ秒の値のことを、本章では「時刻値」と呼びます。\n+`Date`オブジェクトのインスタンスはそれぞれがひとつの時刻値をもち、その時刻値をもとに日付や時・分などを扱うメソッドを提供します。\n+\n+### インスタンスの作成\n+\n+`Date`オブジェクトのインスタンスは、常にnew演算子を使って作成します。\n+`Date`オブジェクトのインスタンス作成には、大きく分けて2つの種類があります。\n+ひとつは現在の時刻をインスタンス化するもの、もうひとつは任意の時刻をインスタンス化するものです。\n+\n+#### 現在の時刻をインスタンス化する\n+\n+`Date`をnewするときにコンストラクタ引数を何も渡さない場合、作成されるインスタンスは現在の時刻を表すものになります。\n+`Date`オブジェクトのインスタンスではなく現在の時刻の時刻値だけが欲しい場合には、`Date.now`メソッドの戻り値を使います。\n+作成したインスタンスがもつ時刻値は、`getTime`メソッドで取得できます。\n+また、`toISOString`メソッドを使うと、その時刻をUTCにおける[ISO 8601][]形式の文字列に変換できます。\n+文字列にすることで人間が見てわかりやすい表示になります。\n+\n+{{book.console}}\n+```js\n+// 現在の時刻を表すインスタンスを作成する\n+const now = new Date();\n+// 時刻値を取得する\n+console.log(now.getTime());\n+// 時刻をISO 8601形式の文字列で表示する\n+console.log(now.toISOString());\n+\n+// 時刻値だけが欲しい場合にはDate.nowメソッドを使う\n+console.log(Date.now());\n+```\n+\n+#### 任意の時刻をインスタンス化する\n+\n+コンストラクタ引数を渡すことで、任意の時刻を表すインスタンスを作成できます。\n+このとき、コンストラクタ引数の渡し方には次の3つの種類があり、用途によって使い分けます。\n+\n+- 時刻値を渡す方法\n+- 時刻を示す文字列を渡す方法\n+- 時刻の部分（年・月・日など）をそれぞれ数値で渡す方法\n+\n+1つめの方法はコンストラクタ関数に数値型の引数をひとつだけ渡したときに適用されます。\n+渡した数値をUTCの1970年1月1日0時0分0秒を基準とした時刻値として扱います。\n+この方法は実行環境による挙動の違いが起きないので安全です。\n+また、時刻値を直接指定するので、他2つの方法と違ってタイムゾーンを考慮する必要がありません。\n+\n+{{book.console}}\n+```js\n+// 時刻のミリ秒値を直接指定する形式\n+// 1136214245999はUTCにおける2006年1月2日15時04分05秒999を表す\n+const date = new Date(1136214245999);\n+// 末尾の'Z'はUTCであることを表す\n+console.log(date.toISOString()); // => \"2006-01-02T15:04:05.999Z\"\n+```\n+\n+2つめの方法は文字列型の引数を渡したときに適用されます。\n+[RFC2822][]や[ISO 8601][]の形式にしたがった文字列を渡すと、\n+その文字列をパースして得られる時刻値を使って、`Date`オブジェクトのインスタンスを作成します。\n+ただし、渡された文字列のパースはブラウザごとに動作が異なることに注意しましょう。\n+また、文字列からタイムゾーンが読み取れないとき、実行環境のタイムゾーンによって時刻値が計算されることにも注意が必要です。\n+なお、時刻値だけが欲しい場合には[Date.parse][]メソッドを使うと、文字列からパースされた時刻値だけを取得できます。\n+\n+{{book.console}}\n+```js\n+// ISO 8601形式の文字列を渡す\n+\n+// UTCにおける2006年1月2日15時04分05秒999を表す文字列\n+const inUTC = new Date(\"2006-01-02T15:04:05.999Z\");\n+console.log(inUTC.toISOString()); // => \"2006-01-02T15:04:05.999Z\"\n+\n+// タイムゾーンの記述がないと実行環境のタイムゾーンを使う\n+// Asia/Tokyo(+09:00)で実行すると、UTCにおける表記は9時間前の06時04分05秒になる\n+const inLocal = new Date(\"2006-01-02T15:04:05.999\");\n+console.log(inLocal.toISOString()); // \"2006-01-02T06:04:05.999Z\" (Asia/Tokyoの場合)\n+\n+// Date.parseメソッドは文字列をパースした時刻値を返す\n+console.log(Date.parse(\"2006-01-02T15:04:05.999Z\")); // => 1136214245999\n+```\n+\n+3つめは、時刻を次のように、年・月・日などの部分ごとの数値で指定する方法です。\n+\n+```js\n+new Date(year, month, day, hour, minutes, seconds, milliseconds);\n+```\n+\n+コンストラクタ関数に2つ以上の引数を渡すとこの方法が使われます。\n+日を表す第3引数から後ろの引数は省略可能ですが、日付だけはデフォルトで1が設定され、その他は0が設定されます。\n+また、月を表す第2引数は0から11までの数値で指定することにも注意しましょう。","path":"source/basic/date/README.md","position":101,"original_position":101,"commit_id":"49d7c417533b3c081b1eee12e9f80bfe1461886d","original_commit_id":"49d7c417533b3c081b1eee12e9f80bfe1461886d","user":{"login":"azu","id":19714,"avatar_url":"https://avatars1.githubusercontent.com/u/19714?v=4","gravatar_id":"","url":"https://api.github.com/users/azu","html_url":"https://github.com/azu","followers_url":"https://api.github.com/users/azu/followers","following_url":"https://api.github.com/users/azu/following{/other_user}","gists_url":"https://api.github.com/users/azu/gists{/gist_id}","starred_url":"https://api.github.com/users/azu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/azu/subscriptions","organizations_url":"https://api.github.com/users/azu/orgs","repos_url":"https://api.github.com/users/azu/repos","events_url":"https://api.github.com/users/azu/events{/privacy}","received_events_url":"https://api.github.com/users/azu/received_events","type":"User","site_admin":false},"body":"Java由来の仕様だ…","created_at":"2017-09-18T11:59:18Z","updated_at":"2017-09-18T11:59:28Z","html_url":"https://github.com/asciidwango/js-primer/pull/289#discussion_r139401693","pull_request_url":"https://api.github.com/repos/asciidwango/js-primer/pulls/289","author_association":"COLLABORATOR","_links":{"self":{"href":"https://api.github.com/repos/asciidwango/js-primer/pulls/comments/139401693"},"html":{"href":"https://github.com/asciidwango/js-primer/pull/289#discussion_r139401693"},"pull_request":{"href":"https://api.github.com/repos/asciidwango/js-primer/pulls/289"}}},"pull_request":{"url":"https://api.github.com/repos/asciidwango/js-primer/pulls/289","id":141439122,"html_url":"https://github.com/asciidwango/js-primer/pull/289","diff_url":"https://github.com/asciidwango/js-primer/pull/289.diff","patch_url":"https://github.com/asciidwango/js-primer/pull/289.patch","issue_url":"https://api.github.com/repos/asciidwango/js-primer/issues/289","number":289,"state":"open","locked":false,"title":"Date object","user":{"login":"lacolaco","id":1529180,"avatar_url":"https://avatars3.githubusercontent.com/u/1529180?v=4","gravatar_id":"","url":"https://api.github.com/users/lacolaco","html_url":"https://github.com/lacolaco","followers_url":"https://api.github.com/users/lacolaco/followers","following_url":"https://api.github.com/users/lacolaco/following{/other_user}","gists_url":"https://api.github.com/users/lacolaco/gists{/gist_id}","starred_url":"https://api.github.com/users/lacolaco/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lacolaco/subscriptions","organizations_url":"https://api.github.com/users/lacolaco/orgs","repos_url":"https://api.github.com/users/lacolaco/repos","events_url":"https://api.github.com/users/lacolaco/events{/privacy}","received_events_url":"https://api.github.com/users/lacolaco/received_events","type":"User","site_admin":false},"body":"Close #125\r\n\r\n","created_at":"2017-09-16T08:44:52Z","updated_at":"2017-09-18T11:59:28Z","closed_at":null,"merged_at":null,"merge_commit_sha":"253e6783cce803bf2996198021bd543995ba3c7a","assignee":null,"assignees":[],"requested_reviewers":[],"milestone":null,"commits_url":"https://api.github.com/repos/asciidwango/js-primer/pulls/289/commits","review_comments_url":"https://api.github.com/repos/asciidwango/js-primer/pulls/289/comments","review_comment_url":"https://api.github.com/repos/asciidwango/js-primer/pulls/comments{/number}","comments_url":"https://api.github.com/repos/asciidwango/js-primer/issues/289/comments","statuses_url":"https://api.github.com/repos/asciidwango/js-primer/statuses/49d7c417533b3c081b1eee12e9f80bfe1461886d","head":{"label":"asciidwango:date-object","ref":"date-object","sha":"49d7c417533b3c081b1eee12e9f80bfe1461886d","user":{"login":"asciidwango","id":10266070,"avatar_url":"https://avatars3.githubusercontent.com/u/10266070?v=4","gravatar_id":"","url":"https://api.github.com/users/asciidwango","html_url":"https://github.com/asciidwango","followers_url":"https://api.github.com/users/asciidwango/followers","following_url":"https://api.github.com/users/asciidwango/following{/other_user}","gists_url":"https://api.github.com/users/asciidwango/gists{/gist_id}","starred_url":"https://api.github.com/users/asciidwango/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/asciidwango/subscriptions","organizations_url":"https://api.github.com/users/asciidwango/orgs","repos_url":"https://api.github.com/users/asciidwango/repos","events_url":"https://api.github.com/users/asciidwango/events{/privacy}","received_events_url":"https://api.github.com/users/asciidwango/received_events","type":"Organization","site_admin":false},"repo":{"id":50896111,"name":"js-primer","full_name":"asciidwango/js-primer","owner":{"login":"asciidwango","id":10266070,"avatar_url":"https://avatars3.githubusercontent.com/u/10266070?v=4","gravatar_id":"","url":"https://api.github.com/users/asciidwango","html_url":"https://github.com/asciidwango","followers_url":"https://api.github.com/users/asciidwango/followers","following_url":"https://api.github.com/users/asciidwango/following{/other_user}","gists_url":"https://api.github.com/users/asciidwango/gists{/gist_id}","starred_url":"https://api.github.com/users/asciidwango/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/asciidwango/subscriptions","organizations_url":"https://api.github.com/users/asciidwango/orgs","repos_url":"https://api.github.com/users/asciidwango/repos","events_url":"https://api.github.com/users/asciidwango/events{/privacy}","received_events_url":"https://api.github.com/users/asciidwango/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/asciidwango/js-primer","description":"JavaScriptの入門書 :book: ","fork":false,"url":"https://api.github.com/repos/asciidwango/js-primer","forks_url":"https://api.github.com/repos/asciidwango/js-primer/forks","keys_url":"https://api.github.com/repos/asciidwango/js-primer/keys{/key_id}","collaborators_url":"https://api.github.com/repos/asciidwango/js-primer/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/asciidwango/js-primer/teams","hooks_url":"https://api.github.com/repos/asciidwango/js-primer/hooks","issue_events_url":"https://api.github.com/repos/asciidwango/js-primer/issues/events{/number}","events_url":"https://api.github.com/repos/asciidwango/js-primer/events","assignees_url":"https://api.github.com/repos/asciidwango/js-primer/assignees{/user}","branches_url":"https://api.github.com/repos/asciidwango/js-primer/branches{/branch}","tags_url":"https://api.github.com/repos/asciidwango/js-primer/tags","blobs_url":"https://api.github.com/repos/asciidwango/js-primer/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/asciidwango/js-primer/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/asciidwango/js-primer/git/refs{/sha}","trees_url":"https://api.github.com/repos/asciidwango/js-primer/git/trees{/sha}","statuses_url":"https://api.github.com/repos/asciidwango/js-primer/statuses/{sha}","languages_url":"https://api.github.com/repos/asciidwango/js-primer/languages","stargazers_url":"https://api.github.com/repos/asciidwango/js-primer/stargazers","contributors_url":"https://api.github.com/repos/asciidwango/js-primer/contributors","subscribers_url":"https://api.github.com/repos/asciidwango/js-primer/subscribers","subscription_url":"https://api.github.com/repos/asciidwango/js-primer/subscription","commits_url":"https://api.github.com/repos/asciidwango/js-primer/commits{/sha}","git_commits_url":"https://api.github.com/repos/asciidwango/js-primer/git/commits{/sha}","comments_url":"https://api.github.com/repos/asciidwango/js-primer/comments{/number}","issue_comment_url":"https://api.github.com/repos/asciidwango/js-primer/issues/comments{/number}","contents_url":"https://api.github.com/repos/asciidwango/js-primer/contents/{+path}","compare_url":"https://api.github.com/repos/asciidwango/js-primer/compare/{base}...{head}","merges_url":"https://api.github.com/repos/asciidwango/js-primer/merges","archive_url":"https://api.github.com/repos/asciidwango/js-primer/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/asciidwango/js-primer/downloads","issues_url":"https://api.github.com/repos/asciidwango/js-primer/issues{/number}","pulls_url":"https://api.github.com/repos/asciidwango/js-primer/pulls{/number}","milestones_url":"https://api.github.com/repos/asciidwango/js-primer/milestones{/number}","notifications_url":"https://api.github.com/repos/asciidwango/js-primer/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/asciidwango/js-primer/labels{/name}","releases_url":"https://api.github.com/repos/asciidwango/js-primer/releases{/id}","deployments_url":"https://api.github.com/repos/asciidwango/js-primer/deployments","created_at":"2016-02-02T05:16:25Z","updated_at":"2017-09-16T03:02:27Z","pushed_at":"2017-09-18T08:39:24Z","git_url":"git://github.com/asciidwango/js-primer.git","ssh_url":"git@github.com:asciidwango/js-primer.git","clone_url":"https://github.com/asciidwango/js-primer.git","svn_url":"https://github.com/asciidwango/js-primer","homepage":"https://asciidwango.github.io/js-primer/","size":4494,"stargazers_count":544,"watchers_count":544,"language":"JavaScript","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":21,"mirror_url":null,"open_issues_count":56,"forks":21,"open_issues":56,"watchers":544,"default_branch":"master"}},"base":{"label":"asciidwango:master","ref":"master","sha":"07e1ce195471a3d8fd3dcf947c36b86fdb459265","user":{"login":"asciidwango","id":10266070,"avatar_url":"https://avatars3.githubusercontent.com/u/10266070?v=4","gravatar_id":"","url":"https://api.github.com/users/asciidwango","html_url":"https://github.com/asciidwango","followers_url":"https://api.github.com/users/asciidwango/followers","following_url":"https://api.github.com/users/asciidwango/following{/other_user}","gists_url":"https://api.github.com/users/asciidwango/gists{/gist_id}","starred_url":"https://api.github.com/users/asciidwango/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/asciidwango/subscriptions","organizations_url":"https://api.github.com/users/asciidwango/orgs","repos_url":"https://api.github.com/users/asciidwango/repos","events_url":"https://api.github.com/users/asciidwango/events{/privacy}","received_events_url":"https://api.github.com/users/asciidwango/received_events","type":"Organization","site_admin":false},"repo":{"id":50896111,"name":"js-primer","full_name":"asciidwango/js-primer","owner":{"login":"asciidwango","id":10266070,"avatar_url":"https://avatars3.githubusercontent.com/u/10266070?v=4","gravatar_id":"","url":"https://api.github.com/users/asciidwango","html_url":"https://github.com/asciidwango","followers_url":"https://api.github.com/users/asciidwango/followers","following_url":"https://api.github.com/users/asciidwango/following{/other_user}","gists_url":"https://api.github.com/users/asciidwango/gists{/gist_id}","starred_url":"https://api.github.com/users/asciidwango/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/asciidwango/subscriptions","organizations_url":"https://api.github.com/users/asciidwango/orgs","repos_url":"https://api.github.com/users/asciidwango/repos","events_url":"https://api.github.com/users/asciidwango/events{/privacy}","received_events_url":"https://api.github.com/users/asciidwango/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/asciidwango/js-primer","description":"JavaScriptの入門書 :book: ","fork":false,"url":"https://api.github.com/repos/asciidwango/js-primer","forks_url":"https://api.github.com/repos/asciidwango/js-primer/forks","keys_url":"https://api.github.com/repos/asciidwango/js-primer/keys{/key_id}","collaborators_url":"https://api.github.com/repos/asciidwango/js-primer/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/asciidwango/js-primer/teams","hooks_url":"https://api.github.com/repos/asciidwango/js-primer/hooks","issue_events_url":"https://api.github.com/repos/asciidwango/js-primer/issues/events{/number}","events_url":"https://api.github.com/repos/asciidwango/js-primer/events","assignees_url":"https://api.github.com/repos/asciidwango/js-primer/assignees{/user}","branches_url":"https://api.github.com/repos/asciidwango/js-primer/branches{/branch}","tags_url":"https://api.github.com/repos/asciidwango/js-primer/tags","blobs_url":"https://api.github.com/repos/asciidwango/js-primer/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/asciidwango/js-primer/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/asciidwango/js-primer/git/refs{/sha}","trees_url":"https://api.github.com/repos/asciidwango/js-primer/git/trees{/sha}","statuses_url":"https://api.github.com/repos/asciidwango/js-primer/statuses/{sha}","languages_url":"https://api.github.com/repos/asciidwango/js-primer/languages","stargazers_url":"https://api.github.com/repos/asciidwango/js-primer/stargazers","contributors_url":"https://api.github.com/repos/asciidwango/js-primer/contributors","subscribers_url":"https://api.github.com/repos/asciidwango/js-primer/subscribers","subscription_url":"https://api.github.com/repos/asciidwango/js-primer/subscription","commits_url":"https://api.github.com/repos/asciidwango/js-primer/commits{/sha}","git_commits_url":"https://api.github.com/repos/asciidwango/js-primer/git/commits{/sha}","comments_url":"https://api.github.com/repos/asciidwango/js-primer/comments{/number}","issue_comment_url":"https://api.github.com/repos/asciidwango/js-primer/issues/comments{/number}","contents_url":"https://api.github.com/repos/asciidwango/js-primer/contents/{+path}","compare_url":"https://api.github.com/repos/asciidwango/js-primer/compare/{base}...{head}","merges_url":"https://api.github.com/repos/asciidwango/js-primer/merges","archive_url":"https://api.github.com/repos/asciidwango/js-primer/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/asciidwango/js-primer/downloads","issues_url":"https://api.github.com/repos/asciidwango/js-primer/issues{/number}","pulls_url":"https://api.github.com/repos/asciidwango/js-primer/pulls{/number}","milestones_url":"https://api.github.com/repos/asciidwango/js-primer/milestones{/number}","notifications_url":"https://api.github.com/repos/asciidwango/js-primer/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/asciidwango/js-primer/labels{/name}","releases_url":"https://api.github.com/repos/asciidwango/js-primer/releases{/id}","deployments_url":"https://api.github.com/repos/asciidwango/js-primer/deployments","created_at":"2016-02-02T05:16:25Z","updated_at":"2017-09-16T03:02:27Z","pushed_at":"2017-09-18T08:39:24Z","git_url":"git://github.com/asciidwango/js-primer.git","ssh_url":"git@github.com:asciidwango/js-primer.git","clone_url":"https://github.com/asciidwango/js-primer.git","svn_url":"https://github.com/asciidwango/js-primer","homepage":"https://asciidwango.github.io/js-primer/","size":4494,"stargazers_count":544,"watchers_count":544,"language":"JavaScript","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":21,"mirror_url":null,"open_issues_count":56,"forks":21,"open_issues":56,"watchers":544,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/asciidwango/js-primer/pulls/289"},"html":{"href":"https://github.com/asciidwango/js-primer/pull/289"},"issue":{"href":"https://api.github.com/repos/asciidwango/js-primer/issues/289"},"comments":{"href":"https://api.github.com/repos/asciidwango/js-primer/issues/289/comments"},"review_comments":{"href":"https://api.github.com/repos/asciidwango/js-primer/pulls/289/comments"},"review_comment":{"href":"https://api.github.com/repos/asciidwango/js-primer/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/asciidwango/js-primer/pulls/289/commits"},"statuses":{"href":"https://api.github.com/repos/asciidwango/js-primer/statuses/49d7c417533b3c081b1eee12e9f80bfe1461886d"}},"author_association":"COLLABORATOR"}}
{"actor":{"display_login":"azu"}}