Format/Prettify/Convert Datetime - dateFormat
File Size: | 79.4 KB |
---|---|
Views Total: | 4805 |
Last Update: | |
Publish Date: | |
Official Website: | Go to website |
License: | MIT |
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="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"> </script> <script src="dist/jquery-dateformat.js"></script>
2. Format a datetime using your own patterns.
$.format.date("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.
jQuery.format.prettyDate("2017-12-25T00:00:01Z") // ==> 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.
Changelog:
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.