15.日付


「RunningJavaScript」を見て学んだ内容です。

名前の日付


✔JavaScriptの日時は、内蔵のDateオブジェクトが担当します.
Dateオブジェクトは最初にJavaからインポートされました.
(「java」スクリプトはjavaに関連する数少ない部分の1つです)
現在の日時を表すオブジェクトを作成する場合はnew Date()を使用します.
const now = new Date();
now;                          // Fri Dec 16 2020 09:20:16 GMT +0900 (KST)
特定の日付のオブジェクトを作成する場合:
const halloween = new Date(2020, 9, 31); // 월은 0에서 시작. 9 ➜ 10.
特定の日時のオブジェクトを作成する場合:
const halloweenParty = new Date(2020, 9, 31, 19, 0); // 19:00 = 7:00 pm
日付オブジェクトを作成すると、次のセクションをインポートできます.
halloweenParty.getFullYear();        // 2021
halloweenParty.getMonth();           // 5
halloweenParty.getDate();            // 8
halloweenParty.getDay();             // 2 (1: 월요일, 0: 일요일)
halloweenParty.getHours();           // 12
halloweenParty.getMinutes();         // 0
halloweenParty.getSeconds();         // 0
halloweenParty.getMillisecounds();   // 0