Visit the date library on npm
The D
class is a utility for working with date instances and formatting.
Creates a new D
instance with a date.
...args
(optional): Arguments to create a new Date instance.
Returns the full 4-digit year of the date.
Returns the 2-digit year (without century) of the date.
Returns the full name of the month.
Returns the abbreviated name of the month (first 3 letters).
Returns the full name of the day of the week.
Returns the abbreviated name of the day of the week (first 3 letters).
Returns the date of the month.
Returns the hours of the date.
Returns the minutes of the date.
Returns the seconds of the date.
Formats the date instance according to the provided format string.
format
(string): The format string specifying how to format the date.
Calculates and returns a human-readable description of the time difference between the date instance and today's date.
const instance = new D(2023, 8, 30);
const formattedDate = instance.format('YYYY-MM-DD');
const timeDifference = instance.when();
console.log(formattedDate); // Outputs: 2023-09-30
console.log(timeDifference); // Outputs: "1 day from now"