概要
JavaScriptにて今月の最終日を取得する方法を簡単にまとめる。
方法
下記のように記載する。
const today = new Date();
const todayYear = today.getFullYear();
const todayMonth = today.getMonth() + 1; // getMonthは1月の場合0を、2月の場合1を返すため+1している。
const lastDay = 0; // 月末日は日付を0に設定することで取得できる。
var endOfMonthDate = new Date(todayYear, todayMonth, lastDay);
console.log(endOfMonthDate);