This npm package offers various utility functions for managing dates in TypeScript. Below, you'll find detailed descriptions of each function along with code examples demonstrating their usage.
formatDateFormats a date object into a string based on the provided format.
date: The date object to format.format: The format string (e.g., 'YYYY-MM-DD HH:mm:ss').The formatted date string.
const { formatDate } = require('auxin');
const date = new Date();
const formattedDate = formatDate(date, 'YYYY-MM-DD HH:mm:ss');
console.log(formattedDate); // Output: '2024-04-21 12:30:45'
getCurrentDateTimeGets the current date and time formatted as a string according to the specified format.
format: The format string (e.g., 'YYYY-MM-DD HH:mm:ss').The formatted current date and time string.
const { getCurrentDateTime } = require('auxin');
const formattedDateTime = getCurrentDateTime('YYYY-MM-DD HH:mm:ss');
console.log(formattedDateTime); // Output: '2024-04-21 12:30:45'
parseDateParses a date string and returns a Date object.
dateString: The date string to parse.The parsed Date object, or null if parsing fails.
const { parseDate } = require('auxin');
const dateString = '2024-04-21';
const parsedDate = parseDate(dateString);
console.log(parsedDate); // Output: Date object for '2024-04-21'
isLeapYearChecks if a given year is a leap year.
year: The year to check.True if the year is a leap year, false otherwise.
const { isLeapYear } = require('auxin');
const year = 2024;
const isLeap = isLeapYear(year);
console.log(isLeap); // Output: true