jQuery Relative Time Plugin for Human-Readable Dates - niceDate

File Size: 17.3 KB
Views Total: 0
Last Update:
Publish Date:
Official Website: Go to website
License: MIT
   
jQuery Relative Time Plugin for Human-Readable Dates - niceDate

niceDate is a lightweight jQuery plugin that converts date strings into human-readable relative time text.

It turns dates into phrases such as "Yesterday," "3 hours ago," or "Tomorrow," refreshes those values at a set interval, and restores the original date text on hover.

Features:

  • Relative minute, hour, and day text for past and future dates.
  • Calendar-date formatting for dates at least 30 days away.
  • Automatic timestamp refresh at a configurable interval.
  • Original date text on mouse hover.
  • Day-only display mode.
  • Custom date parsing through a callback.
  • Configurable month, day, hour, and minute messages.
  • Locale files for Slovenian, Spanish, German, Russian, Turkish, and more.

How To Use It:

1. Download and place the niceDate script after the latest jQuery library.

<script src="/path/to/jquery.min.js"></script>
<script src="/path/to/jquery.niceDate.js"></script>

2. Place the source date inside each element that niceDate should format.

<time class="nice-date">28.09.2026 09:30</time>
<time class="nice-date">03.10.2026 18:00</time>

3. Initialize the plugin and done.

$(function() {
  $('.nice-date').niceDate();
});

4. All plugin configuration options.

  • nowDateObject (Date|null, default null): Sets the date used as the initial reference time. null uses the browser's local time.
  • makeTimestamp (Function): Converts the element text into a JavaScript Date object. Return false for an invalid value.
  • pattern (RegExp): Defines the regular expression used by the built-in date parser.
  • patternOrder (Array, default [3, 2, 1, 4, 5]): Maps matched groups to year, month, day, hour, and minute.
  • dayOnly (Boolean, default false): Uses day-level messages and skips minute and hour output.
  • hoverShow (Boolean, default true): Displays the original element content during mouse hover.
  • autoUpdateInterval (Number, default 60000): Sets the refresh interval in milliseconds. Set it to 0 to disable automatic refresh.
  • monthMessages (Array): Stores the month names used for calendar-date output.
  • dayMessages (Object): Stores past and future text for today, yesterday, tomorrow, and multi-day offsets.
  • hourMessages (Object): Stores singular and plural past and future hour text.
  • minMessages (Object): Stores singular and plural past and future minute text.
$('.article-date').niceDate({
  hoverShow: false,
  autoUpdateInterval: 30000
});

5. Recalculate the relative text using the browser's present time.

$('.nice-date').each(function() {
  $(this).data('plugin_niceDate').update();
});

Alternatives And Related Resources


This awesome jQuery plugin is developed by silvester. For more Advanced Usages, please check the demo page or visit the official website.