let now = new Date();
console.log(now);//→Sat Mar 23 2024 15:34:09 GMT+0900 (日本標準時)
getFullYear()
let now = new Date();
let y = now.getFullYear();
console.log(y); //→2024
getFullYear() メソッドは、指定された日時の年を返します。
getMonth()
let now = new Date();
let m = now.getMonth() + 1; //※0を起点とする為
console.log(m); //→3
getMonth() メソッドは、指定された日付の「月」を表す 0 を基点とした値(すなわち 0 が年の最初の月を示す)を返します。
getDate();
let now = new Date();
let d = now.getDate();
console.log(d);//→23
getDate() メソッドは、指定された日付の「日」を返します。
getDay();
let now = new Date();
let dd = now.getDay();
console.log(dd);//→6 (※土曜日のこと)
let now = new Date();
let dd = now.getDay();
let ddList = ["日", "月", "火", "水", "木", "金", "土"]
console.log(ddList[dd]);//→ 土
getDay() メソッドは、指定された日付の曜日を返します。
0 は日曜日を表します。
getHours();
let now = new Date();
let h = now.getHours();
console.log(h);//→ 16
getHours() メソッドは、指定された日時の「時」を返します。
getMinutes();
let now = new Date();
let mm = now.getMinutes();
console.log(mm);//→9
getMinutes() メソッドは、指定された日時の「分」を返します。
getSeconds();
let now = new Date();
let s = now.getSeconds();
console.log(s);//→1
getSeconds() メソッドは、指定した日時の「秒」を返します。