1.1.0 • Published 3 years ago

@date-js/date-formatter v1.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

Date Formatter

  • A light javascript tool for formatting date (<3kB).
  • Zero dependency.
  • TypeScript compatible.

Example

DateFormatter.format('%l %j %F %Y', new Date());
// Sunday 12 October 2014
DateFormatter.format('%l %j %F %Y', new Date(), 'fr_FR');
// Samedi 12 octobre 2014

By default, Date Formatter uses the current browser language. You can force a locale like this:

DateFormatter.setLocale('fr-FR');

You can see examples in example directory.

Install it

With NPM

npm install @date-js/date-formatter --save
import DateFormatter from '@date-js/date-formatter';

Otherwise

<script src="https://cdn.jsdelivr.net/npm/@date-js/date-formatter@1.0/dist/date-formatter.js"></script>

Format

CharacterDescriptionExample
%YA full numeric representation of a year, 4 digits2020
%yA two digit representation of a year20
%dDay of the month, 2 digits with leading zeros01 to 31
%lA full textual representation of the day of the weekSunday through Saturday
%DA textual representation of a day, three lettersMon through Sun
%FA full textual representation of a month, such as January or MarchJanuary through December
%MA short textual representation of a month, three lettersJan through Dec
%mNumeric representation of a month, with leading zeros01 through 12
%nNumeric representation of a month, without leading zeros1 through 12
%G24-hour format of an hour without leading zeros0 through 23
%H24-hour format of an hour with leading zeros00 through 23
%iMinutes with leading zeros00 to 59
%sSeconds with leading zeros00 to 59