Installation
-
add
pretty-dates.jsto your project files and import it in your HTML code:<script type="text/javascript" src="pretty-dates.js"></script> -
give your HTML elements a correctly formatted
data-datetimeattribute:<span class="pretty-date" data-datetime="1572127200"></span> <!-- timestamp (in seconds) --> or <span class="pretty-date" data-datetime="2019-10-27 08:30:00"></span> -
prettify date:
PrettyDates.on('.pretty-date');
Documentation
PrettyDates object provides many methods:
-
PrettyDates.setLanguage(langCode)sets the language code (e.g.,
'en_US','es_ES'...) for localization purposes -
PrettyDates.setServertime(serverTime)sets the current server time for accurate date calculations (if not provided before enabling Pretty Dates JS, it will use the client time)
parameter
serverTimecan be a timestamp in seconds or a correctly formatted date string -
PrettyDates.on(elements [, autoRefresh])- Parameter
elements -
an array of HTML elements or a query string that selects the elements to be prettified
if query string is
'all', all elements with the classpretty-datewill be selected - Parameter
autoRefresh -
if
true, the prettified dates will automatically refresh every minute
- Parameter
-
PrettyDates.refresh()forces the refresh of all the prettified dates
License
This project is released under MIT license.