Same as "mini" style but outputs "now" instead of "0s". Send mini.json pull requests for the missing languages if you speak those. now ( ) - 12 * 30 * 24 * 60 * 60 * 1000, 'mini' ) // 1 year ago → "1yr"įor best compatibility, mini.json labels should be defined for a locale, otherwise you might end up with labels like "-1m" for "one minute ago" for some languages. format ( new Date ( ) - 1 * 1000, 'mini' ) // 1 second ago → "1s" timeAgo. format ( new Date ( ), 'mini' ) // 0 seconds ago → "0s" timeAgo. Rounds the time up to the closest time measurement unit (second, minute, hour, etc).
While a completely custom "style" could be supplied, this library comes with several built-in "styles" that some people might find useful.įollowing is the list of built-in "styles". Such configuration comes under the name of "style". ago", ".m"), or should it use custom ones, or should it skip using relative time labels in some cases and instead output something like "Dec 11, 2015". What labels should be used: should it use the standard built-in labels for the languages ( ". What scale should be used for measuring time intervals: should it be precise down to the second, or should it only measure it up to a minute, or should it start from being more precise when time intervals are small and then gradually decrease its precision as time intervals get longer. This library allows for any custom logic for formatting time intervals: addDefaultLocale ( ru ) const timeAgo = new TimeAgo ( 'ru-RU' ) timeAgo. import ru from 'javascript-time-ago/locale/ru.json' TimeAgo. Import TimeAgo from 'javascript-time-ago' // Russian. The "default language" is "en" by default, and can be set either by calling addDefaultLocale(): If the "default language" hasn't been added, an error is thrown. If none of the added languages match the locale, the "default language" is used. For example, locales "en-US" and "en-GB" both match "en" language.
The locale argument of new TimeAgo(locale) constructor is matched against the list of added languages, and the first matching one is used. Languages should be imported from javascript-time-ago/locale and then added via TimeAgo.addLocale() or TimeAgo.addDefaultLocale(). No languages are loaded default: a developer must manually choose which languages should be loaded. This library includes date/time formatting rules and labels for any language. format ( new Date ( ) ) // "just now" timeAgo. const timeAgo = new TimeAgo ( 'en-US' ) timeAgo. addDefaultLocale ( en ) // Create formatter (English). import en from 'javascript-time-ago/locale/en.json' TimeAgo. Import TimeAgo from 'javascript-time-ago' // English.