Skip to content

👨‍💻⏱ A small package to format date object by providing a template to parse and rendering it anytime, anywhere with any date object.

Notifications You must be signed in to change notification settings

JayMGurav/FormaDateTime

Repository files navigation

FormaDateTime

Parse and render date/time to human readable form. Just provide a string with below mentioned Identifiers in {} as {MMMM} once, and render it anywhere/any number of times with any date object. Since the passed string/template is parsed once and can be rendered any number of times with whatever date obj provided, which makes it performant, flexible and easy to use. For different templates we have to create new instance.

Identifiers

  • MMMM: Full Month (January)
  • MM: Partial Month (Jan)
  • Mo: Numeric Month (01)
  • YYYY: Full Year (2021)
  • YY: Partial Year (21)
  • dddd: Day of the Week (Monday)
  • DD: Day of the Month (15)
  • Do: Day (15th)
  • h: Hours - 12h format (06)
  • H: Hours - 24h format (18)
  • mm: Minutes -zero padded(05)
  • ss: Seconds -zero padded (05)
  • pa: AM/PM

Options

<!-- default options -->
options : {
  padMonth : true,
  padDays: true,
  padHours: true
}

Usage

const publishedOn = new FormatDateTime("Published on: {Do} {MMMM} {YYYY}", {
  padMonth : true,
  padDays: true,
  padHours: true
});
console.log(publishedOn.render(new Date())); //Published on: 24th December 2012

About

👨‍💻⏱ A small package to format date object by providing a template to parse and rendering it anytime, anywhere with any date object.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published