DateTimeFormatter
A simple and flexible TypeScript package for formatting dates and times. The DateTimeFormatter
class allows you to format dates in various formats, handle both Date
objects and date strings, and includes features for easy integration into your projects.
Features
- Format dates to multiple formats:
- MM/DD/YYYY
- DD-MM-YYYY
- YYYY-MM-DD
- Format time to HH:MM:SS
- Combine date and time formatting
- Accepts both
Date
objects and date strings as input
Installation
To install the package, you can use npm or yarn:
npm install datematic
Usage
(async () => {
const formatter = new DateTimeFormatter();
await formatter.init();
const now = new Date();
console.log(formatter.formatUSDate(now));
console.log(formatter.formatUSDate("2024-11-19"));
console.log(formatter.formatDateDDMMYYYY(now));
console.log(formatter.formatDateDDMMYYYY("2024-11-19"));
console.log(formatter.formatDateYYYYMMDD(now));
console.log(formatter.formatDateYYYYMMDD("2024-11-19"));
console.log(formatter.formatTime(now));
console.log(formatter.formatTime("2024-11-19T12:34:56"));
console.log(formatter.formatDateTime(now));
})();