datematic
v0.0.1
Published
Date and time formatting in a flash
Downloads
28
Maintainers
Readme
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(); // Initialize the core if needed
const now = new Date();
console.log(formatter.formatUSDate(now)); // Output: MM/DD/YYYY
console.log(formatter.formatUSDate("2024-11-19")); // Output: 11/19/2024
console.log(formatter.formatDateDDMMYYYY(now)); // Output: DD-MM-YYYY
console.log(formatter.formatDateDDMMYYYY("2024-11-19")); // Output: 19-11-2024
console.log(formatter.formatDateYYYYMMDD(now)); // Output: YYYY-MM-DD
console.log(formatter.formatDateYYYYMMDD("2024-11-19")); // Output: 2024-11-19
console.log(formatter.formatTime(now)); // Output: HH:MM:SS
console.log(formatter.formatTime("2024-11-19T12:34:56")); // Output: 12:34:56
console.log(formatter.formatDateTime(now)); // Output: MM/DD/YYYY HH:MM:SS
})();