Format JavaScript Date Strings – format-date

Category: Date & Time , Javascript | July 23, 2020
Author:VitorLuizC
Views Total:43 views
Official Page:Go to website
Last Update:July 23, 2020
License:MIT

Preview:

Format JavaScript Date Strings – format-date

Description:

format-date is a super tiny (~0.4kb) JavaScript library to format JavaScript date() strings using custom Date and Time patterns:

  • YY: 20
  • YYYY: 2020
  • M: 7
  • MM: 07
  • D: 1
  • DD: 01
  • H: 1
  • HH: 01
  • m: 1
  • mm: 01
  • s: 1
  • ss: 01
  • *: Escape

How to use it:

1. Install the format-date.

# Yarn
$ yarn add @bitty/format-date

# NPM
$ npm i @bitty/format-date --save

2. Import the format-date as a module.

import formatDate from '@bitty/format-date';

3. Or from a CDN.

<script type="module">
  import formatDate from 'https://cdn.jsdelivr.net/npm/@bitty/[email protected]/dist/format-date.esm.js';
</script>

4. Format a date and determine the Date and Time patterns as follows:

formatDate(new Date(), 'YYYY-MM-DD-HH-mm-ss')
=> 2020-07-23-13-55-00

You Might Be Interested In:


Leave a Reply