1
0

JavaScript 「今月の最終日」を取得するコード

Last updated at Posted at 2024-03-28

概要

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);
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0