Format/Prettify/Convert Datetime - dateFormat

File Size: 79.4 KB
Views Total: 3988
Last Update:
Publish Date:
Official Website: Go to website
License: MIT
Format/Prettify/Convert Datetime - dateFormat

dateFormat is a small and fast JavaScript library used to format, prettify and convert datetime with different patterns.

The JavaScript library can be used as a jQuery plugin or a Vanilla JS plugin.

Main features:

  • Converts any kind of date into a formatted date.
  • Converts timestamps to a human-readable format, e.g: " 1 day ago".
  • Converts a date into browsers timezone.
  • Easy to style using your own CSS.
  • Supports ISO 8601, RFC 2822 and JavaScript Date Object

How to use it:

1. Include the necessary dateFormat library on the webpage.

<!-- Use as a pure JS plugin -->
<script src="dist/dateFormat.js"></script>

<!-- Use as a jQuery plugin -->
<script src="" 
<script src="dist/jquery-dateformat.js"></script>

2. Format a datetime using your own patterns.

$"2018-05-10T01:10:20+02:00", "dd/MM/yyyy")

// ==> 05/10/2018

3. Formate a datetime so that it displays how long ago the given time was compared to now.


// ==> more than 5 weeks ago

4. Display a datetime in the local timezone

$.format.toBrowserTimeZone("2013-09-14T23:22:33Z", dateFormat)

// ==> 09/15/2013 07:22:33

Date and Time Patterns:

  • yy: short year18
  • yyyy: long year 2018
  • M: month (1-12)
  • MM: month (01-12)
  • MMM: month abbreviation (Jan, Feb)
  • MMMM: long month (January, February)
  • d: short day (1 - 31)
  • dd: day (01 - 31)
  • ddd: day of the week (Monday, Tuesday)
  • E: short week (Mon, Tue ... Sun)
  • D: Ordinal day (1st, 2nd, 3rd)
  • h: hour in am/pm (0-12)
  • hh: hour in am/pm (00-12)
  • H: hour in day (0-23)
  • HH: hour in day (00-23)
  • mm: minute
  • ss: second
  • SSS: milliseconds
  • a: AM/PM
  • p: a.m./p.m.


v1.0.4 (2019-08-02)

  • Fix time formatting with some environments

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