Answer the question
In order to leave comments, you need to log in
Change date and time dynamically since publication in Yii2, how to do it?
Hello.
--
Background: I noticed how in the social network "in contact", the date and time are updated from the moment the post was published. Roughly speaking, you scroll through your feed, the page does not reload, you write comments, put likes, and you see that the inscription changes for each block individually:
"опубликовано только что"
"опубликовано пять минут назад"
"опубликовано вчера в 13:16"
Answer the question
In order to leave comments, you need to log in
There can be at least 1000 blocks on the page, but the user always sees only a certain number of them. Therefore, for good, you need to update the statute of limitations not for all the blocks displayed on the page, but only for those that are visible to the user. Accordingly, you need to:
1. Determine (for example, when scrolling the page) which blocks are currently visible to the user
2. Define an array of selectors for each block
3. Loop through this array and recalculate the date for each block
And what does yii have to do with it? This is a js question. Everything that happens in the browser is js. Yii stores and retrieves time data from the database and does not change it. Changes them js, timer or scroll.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question