C
C
Coder3212016-10-03 18:28:48
JavaScript
Coder321, 2016-10-03 18:28:48

How to format the date?

I have an array of dates, I need to format them into the format "1 minute ago", "2 minute ago", "1 hour ago", "1 day ago" from the user's local timezone. How to do this?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
P
Pavel, 2016-10-03
@Coder321

momentjs.com

P
Peter, 2016-10-03
@petermzg

var ms = (new Date()).valueOf(); // текущее время в ms от 01 января 1970
var secs = (ms - youdate.valueOf()) / 1000; // разница в секундах

Далее разберетесь

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question