1
1

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 3 years have passed since last update.

Moment.jsについて 備忘録

Last updated at Posted at 2020-07-31

日付操作のライブラリMoment.js

今現在のの日付を取得する
・moment();

文字列からオブジェクトを生成する
・moment('2020-06-01 00:00:00');

日時の加減算
加算
・moment().add(数字,文字('y'/'M'/'w'/'d'/'h'/'m'/'s'));
減算
・moment().subtract(数字,文字('y'/'M'/'w'/'d'/'h'/'m'/'s'));

日時の比較
a = moment('2018-09-01 06:00:00')
b = moment('2018-10-01 06:00:00')
c = moment('2018-11-01 06:00:00')

b.isAfter(a) // true
b.isAfter(b) // false
b.isAfter(c) // false

b.isSame(a) // false
b.isSame(b) // true
b.isSame(c) // false

b.isBefore(a) // false
b.isBefore(b) // false
b.isBefore(c) // true

b.isSameOrAfter(a) // true
b.isSameOrAfter(b) // true
b.isSameOrAfter(c) // false

b.isSameOrBefore(a) // false
b.isSameOrBefore(b) // true
b.isSameOrBefore(c) // true

b.isBetween(a, c) // true
c.isBetween(a, b) // false

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?