XDate - Modern JavaScript Date Library (Circa 2013)

0.8.3 · deprecated · verified Sun Apr 19

XDate is a lightweight JavaScript date library released circa 2013, designed as a thin wrapper around the native `Date` object to provide enhanced functionality for parsing, formatting, and manipulating dates. It aims for familiarity by implementing many of the same methods as the native `Date` object and is non-destructive to the DOM, making it safe for inclusion in third-party libraries. The current stable version is 0.8.3, but the package is explicitly no longer actively maintained. The original author recommends migrating to `temporal-polyfill`, which implements the modern JavaScript Temporal API standard, as a direct replacement. Given its deprecated status, XDate does not have an active release cadence and lacks modern JavaScript features like native ESM support.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates basic usage of XDate, including creating, manipulating, formatting, and differencing dates using its CommonJS interface. Also highlights the deprecated status.

const XDate = require('xdate'); // Use CommonJS require

// Create a new XDate object for the current date and time
const now = new XDate();
console.log('Current XDate:', now.toString());

// Manipulate the date: add 7 days (returns a new XDate instance)
const futureDate = now.clone().addDays(7);
console.log('Date 7 days from now:', futureDate.toDateString());

// Format the date using a custom string
const formattedDate = futureDate.toString('yyyy-MM-dd HH:mm:ss');
console.log('Formatted future date (YYYY-MM-DD HH:MM:SS):', formattedDate);

// Calculate the difference between two dates in days
const today = new XDate();
const tomorrow = today.clone().addDays(1);
const diffInDays = tomorrow.diffDays(today);
console.log(`Difference between tomorrow and today in days: ${diffInDays}`);

// Create a date from an ISO string
const specificDate = new XDate('2025-12-25T12:00:00Z');
console.log('Specific XDate (Christmas 2025 UTC):', specificDate.toUTCString());

/*
NOTE: This library is deprecated and no longer actively maintained.
For new projects, it is strongly recommended to use a modern alternative
such as 'temporal-polyfill' which implements the ECMAScript Temporal API.
*/

view raw JSON →