A versatile and efficient JavaScript library for formatting date and time.
- Date Formatting: Customize the output format for dates.
- Name of Months: Input custom names for months.
- Day Increment/Decrement: Modify the date by incrementing or decrementing days.
- Weekday Formatting: Control how weekdays are displayed with localization and other options.
- Time Formatting: Format time with support for 12-hour or 24-hour formats.
- Valid Time Formats: Use predefined valid time formats for ease of use.
Install tictic
via npm:
npm install tictic --save
Here's how you can use tictic to format dates:
import { getFormattedDate } from 'tictic'
const formattedDate = getFormattedDate({
date: new Date(),
sep: '-',
format: 'DD-MM-YYYY',
exclude: { year: false, month: false, day: false, zero: false },
nameOfMonths: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
weekDays: {
set: true,
locale: 'en',
format: 'short',
case: 'uppercase',
position: 'end'
},
incDay: 1
});
console.log(formattedDate); // Outputs something like: "15-JAN-2023 SUN"
Formatting time is straightforward as well:
import { getFormattedTime } from 'tictic'
const formattedTime = getFormattedTime({
time: new Date().getTime(),
sep: ':',
format: 'hh:mm:ss',
meridiem: {
format: '12h',
case: 'uppercase',
position: 'end',
}
});
console.log(formattedTime); // Outputs something like: "01:45:20 PM"
API Reference
For a deep dive into each method and its options, please refer to the source code documentation. It provides clear details about each configuration property and its possible values.
This project is licensed under the GNU General Public License v3.0 (GPL-3.0). See LICENSE.md for more details.