Lightweight Datetime Formatter In JavaScript – tinydate

Category: Date & Time , Javascript , Recommended | June 8, 2019
Author: lukeed
Views Total: 60
Official Page: Go to website
Last Update: June 8, 2019
License: MIT


Lightweight Datetime Formatter In JavaScript – tinydate


tinydate is an extremely lightweight (0.3 kb minified) JavaScript library used for formatting date/time strings using pure JavaScript.

How to use it:

Install the tinydate package & import the module.

$ npm install tinydate --save
import tinydate from 'tinydate';

Or directly import the tinydate library from the CDN.

<script src="[email protected]/dist/tinydate.min.js"></script>

Specify the date/time you want to format.

const myDate = new Date('6/8/2019, 3:54:01 PM');

Set the pattern to format the date/time. All possible patterns:

  • MM – Partial Month (Sep)
  • YYYY – Full Year (1992)
  • YY – Partial Year (92)
  • DD – Day of the Month (24)
  • HH – Hours – 24h format
  • mm – Minutes (zero padded)
  • ss – Seconds (zero padded)
  • fff – Milliseconds
const myPattern = tinydate('Current time: [{HH}:{mm}:{ss}]');

Output the formatted date/time.


You Might Be Interested In:

Leave a Reply