74
69

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

JavaScriptで月末日を取得する

Last updated at Posted at 2014-01-30

概説

タイトルの通り、JavaScriptで月末日を取得します。

今月の末日を取得する

JavaScript
var dt = new Date(); // 「今日」のインスタンスを取得
console.log(dt); // Thu Jan 30 2014 00:00:00 GMT+0900 (東京 (標準時)) 

console.log(new Date(dt.getFullYear(), dt.getMonth() + 1, 0)); // Fri Jan 31 2014 00:00:00 GMT+0900 (東京 (標準時))

先月の末日を取得する

JavaScript
console.log(new Date(dt.getFullYear(), dt.getMonth(), 0)); // Tue Dec 31 2013 00:00:00 GMT+0900 (東京 (標準時))

翌月の末日を取得する

JavaScript
console.log(new Date(dt.getFullYear(), dt.getMonth() + 2, 0)); // Fri Feb 28 2014 00:00:00 GMT+0900 (東京 (標準時))

参考URL

JavaScriptで月末日を取得する方法
JavaScriptで指定した年月の月末日を取得する
JavaScriptで月末日を取得する

74
69
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
74
69

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?