2
3

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の日付ライブラリXDateで、何週間前を計算する。

Posted at

やりたいこと

javascriptの日付算出には、ちょっと手間がかかるのでXDateを使って簡略化する。

本家サイト

XDate

日付算出

ちょっとつまづいたのが、月を-1するところ。ここは、どうしようもないのか。

    var bd = String(baseDate);
    var yy = bd.substring(0,4);
    var mm = bd.substring(4,6);
    var dd = bd.substring(6,8);
    var xd = new XDate(yy,Number(mm)-1,dd);
    xd.addWeeks(1);
    var day = xd.toString("yyyyMMdd");

その他

本家サイトをみればわかるが、他にも年月日時分秒の足し算、引き算が可能。
引き算は、マイナスを指定する。

2
3
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
2
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?