📜 ⬆️ ⬇️

uptodate.js is a library for auto updating time elements

How often do you use designs like "5 minutes ago", "Half an hour ago" on your site? And what if the user opened the tab and forgot about it for a couple of hours? “5 minutes ago” clearly loses its relevance.
It is to correct this unfortunate misunderstanding that uptodate.js serves.

image


')

Using



  1. Prepare timestamps in content.
    By default, uptodate takes a value from the data-time attribute that must contain a timestamp (number of milliseconds since epoch (00:00:00 UTC on 1970 January 1970))
    for example
    Posted: <span class="uptodate" data-time="1367180233904"> 4 minutes ago <span> 

  2. Deploy the library.
    All you need to do is call the only uptodate () method.
    You can transfer optional parameters to the call, the list of which is available on the office
    For example:
      <script src="js/uptodate.js"> <script type="text/javascript"> window.onload = function() { uptodate(); }; </script> 




Offsite | Github

PS In order for the lib to work with the Russian language, you must pass the custom time_ago_in_words method in the parameters: https://github.com/prezjordan/uptodate/blob/master/uptodate.js#L69
PSS datacompboy suggested an analogue - libu timeago, which already includes Russian localization. Offsite | Github

Source: https://habr.com/ru/post/178427/


All Articles