LoginSignup
0
1

More than 5 years have passed since last update.

現在時刻からx日後のy時までの差分を取る。

Last updated at Posted at 2017-08-01

たまに使うのでメモ。
サンプルは翌日の9時00分まで。

デモ

1. Dateでやる場合

const now = new Date();
const expire = new Date(now.getFullYear(), now.getMonth(), now.getDate() + 1, 9, 0, 0);
const diff = expire - now

2. Moment.jsを使う場合

const now = moment();
const expire = moment().add(1, 'd').set({ h: 9, m: 0, s: 0, ms: 0 });
const diff = expire.diff(now)
0
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
0
1