Hello.

I use the library of moment.js . I'm trying to get the time difference in the right format. And I just can not figure out how to combine, one with the other. At the moment I have:

 moment.lang('ru'); // результат будет: 2016-03-30 23:59:57 $('.block').html(moment('2016-03-30 23:59:57').format('YYYY-MM-DD HH:mm:ss')); // результат будет: месяц назад $('.block').html(moment('2016-03-30 23:59:57').fromNow()); 

I'm trying to get something like that 0000-00-27 06:58:52 - here the amount of time has passed since the date specified in .moment (...). Simply put, you need to show in this format: YYYY-MM-DD HH:mm:ss time difference.

What needs to be done to realize the date output in the right format?

    1 answer 1

     var moment = require('moment'); moment.locale('ru'); var now = moment(); var event = moment('2016-03-30 23:59:57'); console.log('Сегодня: ' + now.format('YYYY-MM-DD HH:mm:ss')); console.log('Дата события: ' + event.format('YYYY-MM-DD HH:mm:ss')); console.log('Событие произошло ' + event.fromNow()); console.log('Разница во времени: ' + now.subtract(event.toObject()).format('YYYY-MM-DD HH:mm:ss')); 
    • require() removed, works fine without it. Thank! - PoyCc
    • Yeah. require is for NodeJS :) - Beast Winterwolf
    • By the way, I don’t know what is wrong with this one, but today, today, minus today for some reason returns 0000-01-30 00:00:00, so you probably still need to subtract this time! - Beast Winterwolf