17
17

More than 5 years have passed since last update.

JavaScriptのモダンな日付ライブラリらしいXDateで月初、月末を計算する

Posted at

本家

XDate

月初

var xd = new XDate();
alert(xd.toString("yyyy-MM-01"));

月末

var xd = new XDate();
xd.addMonths(1);
xd.setDate(0);
alert(xd.toString("yyyy-MM-dd"));

※javascriptのDate関数に翌月の日付を0で渡すと、今月の月末日が取得できるという技がXDateでも利用できました。
ただ、XDateのページには、setDateのパラメーターは、1-31とあるのでバグなのかもしれません。

17
17
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
17
17