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 stringsparse()
- Parse date strings into Date objectscompile()
- Precompile format strings for performancepreparse()
- Parse date strings and return intermediate resultsisValid()
- Validate date string formatstransform()
- Transform date strings between different formats
Date Arithmetic โ
addYears()
,addMonths()
,addDays()
- Date additionaddHours()
,addMinutes()
,addSeconds()
,addMilliseconds()
- Time additionsubtract()
- Calculate time differences with Duration objects
Utility Functions โ
isLeapYear()
- Check if a year is a leap yearisSameDay()
- 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 โ
Browser | Minimum Version |
---|---|
Chrome | 85+ |
Firefox | 78+ |
Safari | 14+ |
Edge | 85+ |
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.