Answer the question
In order to leave comments, you need to log in
How to display the publication date using js. by type, posted today, an hour ago, a day ago?
Hello! Please tell me how to implement the output of the publication date, which will change each time something like (published 20 minutes ago; 1 hour ago; a day ago), etc. in which direction to look for the answer? What a day I've been fighting. Thanks in advance.
Answer the question
In order to leave comments, you need to log in
https://momentjs.com/
Use moment or its analogues, which are not few on the market. The moment is one of the most convenient.
First you need to calculate the difference between that date and the current time. The easiest way is to convert both dates into something like "number of milliseconds since Unix epoch" Then we have to decide which interval we round to minutes, which to hours, etc. Well, round it up.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question