@eli-90/date-lab

1.0.1 • Public • Published

Date Library Documentation

License: MIT

npm version

Visit the date library on npm

Bundle Size

GitHub issues

The D class is a utility for working with date instances and formatting.

Constructor

constructor(...args)

Creates a new D instance with a date.

  • ...args (optional): Arguments to create a new Date instance.

Properties

year

Returns the full 4-digit year of the date.

yr

Returns the 2-digit year (without century) of the date.

month

Returns the full name of the month.

mon

Returns the abbreviated name of the month (first 3 letters).

day

Returns the full name of the day of the week.

dy

Returns the abbreviated name of the day of the week (first 3 letters).

date

Returns the date of the month.

hours

Returns the hours of the date.

mins

Returns the minutes of the date.

secs

Returns the seconds of the date.

Methods

format(format)

Formats the date instance according to the provided format string.

  • format (string): The format string specifying how to format the date.

when()

Calculates and returns a human-readable description of the time difference between the date instance and today's date.

Example Usage

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"

/@eli-90/date-lab/

    Package Sidebar

    Install

    npm i @eli-90/date-lab

    Weekly Downloads

    0

    Version

    1.0.1

    License

    ISC

    Unpacked Size

    97 kB

    Total Files

    16

    Last publish

    Collaborators

    • eli-90