Skip to content

lib-package/date-formatter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Date Formatter

dateFormatter is a simple utility function to format JavaScript Date objects into readable strings based on specified locales and formatting options. It leverages the Intl.DateTimeFormat API to provide flexible and locale-aware date formatting.

Installation

Use with npm:

npx jsr add @jhenbert/date-formatter

Usage

import * as mod from "@jhenbert/date-formatter"

Example

// Format a date as "July 4, 2023" in US English locale
const locale = "en-US";
const options = { year: "numeric", month: "long", day: "numeric" };
const date = new Date("2023-07-04");

console.log(mod.default(locale, options, date));
// Output: "July 4, 2023"

// Format a date as "Hulyo 4, 2023" in Philippines locale
const localePh = "fil-PH";
const optionsPh = { year: "numeric", month: "long", day: "numeric" };
const datePh = new Date("2023-07-04");

console.log(mod.default(localePh, optionsPh, datePh));
// Output: "Hulyo 4, 2023"

About

Format the date according to your local settings.

Resources

License

Stars

Watchers

Forks

Packages

No packages published