Lightweight Datetime Formatter In JavaScript – tinydate

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

Preview:

Lightweight Datetime Formatter In JavaScript – tinydate

Description:

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
$ npm install tinydate --save
import tinydate from 'tinydate';

Or directly import the tinydate library from the CDN.

<script src="https://unpkg.com/tinydate@latest/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.

myPattern(myDate);

Changelog:

v1.3.0 (06/30/2019)

  • Add TypeScript definitions

v1.2.0 (07/30/2019)

  • Allow custom patterns

You Might Be Interested In:


Leave a Reply