Skip to content

Introduction โ€‹

date-and-time is the simplest, most intuitive date and time library for JavaScript and TypeScript. Built from the ground up with modern development practices, it provides a comprehensive set of tools for date manipulation, formatting, parsing, and timezone handling.

Why date-and-time? โ€‹

๐Ÿš€ Modern & Performant โ€‹

  • Written entirely in TypeScript with ES2021 target
  • Tree-shakable modules for optimal bundle size
  • Zero dependencies for core functionality
  • Full ES Modules and CommonJS support

๐ŸŒ Internationalization Ready โ€‹

  • Support for 40+ locales with native month/day names
  • Multiple calendar systems (Gregorian, Buddhist)
  • Numeral systems (Latin, Arabic, Bengali, Myanmar)
  • Timezone-aware formatting and parsing

๐ŸŽฏ Developer Experience โ€‹

  • Full TypeScript support with comprehensive type definitions
  • IntelliSense support in modern editors
  • Consistent API design across all functions
  • Extensive documentation and examples

๐Ÿ“ฆ Production Ready โ€‹

  • Node.js 18+ support
  • Modern browser compatibility (Chrome 85+, Firefox 78+, Safari 14+)
  • Comprehensive test suite with high coverage
  • Battle-tested in production environments

Key Features โ€‹

Formatting and Parsing โ€‹

  • format() - Convert Date objects to formatted strings
  • parse() - Parse date strings into Date objects
  • compile() - Precompile format strings for performance
  • preparse() - Parse date strings and return intermediate results
  • isValid() - Validate date string formats
  • transform() - Transform date strings between different formats

Date Arithmetic โ€‹

  • addYears(), addMonths(), addDays() - Date addition
  • addHours(), addMinutes(), addSeconds(), addMilliseconds() - Time addition
  • subtract() - Calculate time differences with Duration objects

Utility Functions โ€‹

  • isLeapYear() - Check if a year is a leap year
  • isSameDay() - Check if two dates are on the same day

Advanced Features โ€‹

  • Timezone Support - Comprehensive timezone data from timezonedb
  • Locale Support - 40+ languages with native formatting
  • Plugin System - Extensible with microsecond/nanosecond precision
  • Duration Objects - Rich time difference calculations

Version 4.x Highlights โ€‹

Version 4.x represents a complete rewrite with significant improvements:

๐Ÿ”„ Breaking Changes โ€‹

  • TypeScript-first development approach
  • Integrated plugins - timezone and timespan functionality built-in
  • New API signatures - options objects replace boolean parameters
  • Modern JavaScript - ES2021 features throughout

๐Ÿ“ˆ Performance Improvements โ€‹

  • Reduced bundle size with tree-shaking

๐Ÿ›  Developer Improvements โ€‹

  • Expanded language support - Now supporting 40+ locales
  • Improved TypeScript inference and completion
  • Comprehensive documentation with live examples

Architecture โ€‹

typescript
import { format, parse } from 'date-and-time';
import ja from 'date-and-time/locales/ja';
import Tokyo from 'date-and-time/timezones/Asia/Tokyo';

// Core functionality
const date = new Date();
const formatted = format(date, 'YYYY/MM/DD');

// Localized formatting
const localized = format(date, 'YYYYๅนดMๆœˆDๆ—ฅ', { locale: ja });

// Timezone-aware operations
const tokyoTime = format(date, 'YYYY-MM-DD HH:mm:ss', { timeZone: Tokyo });

Browser and Environment Support โ€‹

Node.js โ€‹

  • Node.js 18.0.0+ (LTS recommended)
  • Full ES Modules support
  • CommonJS compatibility

Browsers โ€‹

BrowserMinimum Version
Chrome85+
Firefox78+
Safari14+
Edge85+

Module Systems โ€‹

  • ES Modules (.mjs, type: "module")
  • CommonJS (.cjs, traditional Node.js)
  • TypeScript (4.5+)
  • Bundlers (Webpack, Rollup, Vite, etc.)

Getting Started โ€‹

Ready to start using date-and-time? Continue to the Installation Guide to set up the library in your project.

Released under the MIT License.