moment.js date output

Hello.

I use the moment.js library. I'm trying to display the time difference in the desired format. And here I can not understand 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 output something like this 0000-00-27 06:58:52 - here the amount of time that has passed since the date specified in .moment (...). Simply put, you need to show the time difference in this format: YYYY-MM-DD HH:mm:ss.

What you need to do to implement the date output in the desired format?

Author: PoyCc, 2016-04-30

1 answers

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'));
 5
Author: Beast Winterwolf, 2016-04-30 04:24:34