LoginSignup
0
0

More than 5 years have passed since last update.

moment.jsで経過時間を年+月+日+時+分で表示させる

Last updated at Posted at 2016-04-13

moment.js + moment-precise-range というプラグインが便利でした。
年、月、日、時、分をそれぞれ数値だけ取得するには下記のように記述する。

js
var from = moment('2016-04-09 12:00:00');
var to = moment(); // now
var diff = moment.preciseDiff(from to, true); // fromからtoまでの経過日数を数値で取得

var d{
  Y = ('0' + diff.years).slice(-2),
  Mo = ('0' + diff.months).slice(-2),
  D = ('0' + diff.days).slice(-2),
  Mi = ('0' + diff.minutes).slice(-2),
  S = ('0' + diff.seconds).slice(-2)
};
0
0
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
0