Best Date-Time Libraries by Programming Language
Comprehensive guide to the best datetime libraries for every major programming language. Find the right library for timezone handling, timestamp conversion, and date arithmetic.
🟨 JavaScript / TypeScript
Luxon
RecommendedModern, immutable datetime library built on the Intl API with excellent timezone support
Bundle Size: 71 KB (minified)
Best for: Production apps requiring accurate timezone handling
Features & Details
Key Features
- Immutable DateTime objects
- Full IANA timezone database support
- Duration and Interval calculations
- Locale-aware formatting
- Built on native Intl API
- TypeScript support
Pros
- Best timezone support
- Modern API
- Active development
- Smaller than Moment
Cons
- Larger than Day.js
- Requires learning new API
- IE11 needs polyfill
Code Example
import { DateTime } from 'luxon';
const dt = DateTime.now().setZone('America/New_York');
const iso = dt.toISO();
const unix = dt.toSeconds();
Day.js
RecommendedLightweight Moment.js alternative with plugin architecture
Bundle Size: 2 KB (core, gzipped)
Best for: Bundle-size critical applications
Features & Details
Key Features
- Moment.js-compatible API
- Plugin architecture
- Extremely small bundle size
- Immutable
- Timezone support via plugin
- I18n support
Pros
- Tiny bundle size
- Familiar API
- Good performance
- Easy migration from Moment
Cons
- Requires plugins for features
- Timezone plugin adds size
- Smaller ecosystem
Code Example
import dayjs from 'dayjs';
import timezone from 'dayjs/plugin/timezone';
dayjs.extend(timezone);
const time = dayjs().tz('America/New_York').format();
date-fns
RecommendedFunctional programming approach with tree-shakeable functions
Bundle Size: Tree-shakeable (10-30 KB typical)
Best for: Functional programming patterns and tree-shaking
Features & Details
Key Features
- Over 200 pure functions
- Tree-shakeable
- Immutable
- TypeScript support
- Timezone support via date-fns-tz
- Locale support
Pros
- Modular
- Functional API
- Tree-shakeable
- Great TypeScript support
Cons
- Separate package for timezones
- Verbose for simple tasks
- Different API style
Code Example
import { format, parseISO } from 'date-fns';
import { utcToZonedTime } from 'date-fns-tz';
const date = utcToZonedTime(new Date(), 'America/New_York');
const formatted = format(date, 'yyyy-MM-dd HH:mm:ssXXX');
Moment.js
Deprecated (Maintenance Mode)Legacy datetime library (no longer recommended for new projects)
Bundle Size: 67 KB (minified)
Best for: Legacy projects only (migrate to Luxon/Day.js)
Features & Details
Key Features
- Comprehensive date manipulation
- Timezone support (moment-timezone)
- Locale support
- Relative time
- Duration calculations
Pros
- Mature ecosystem
- Extensive documentation
- Large community
Cons
- Deprecated
- Mutable API
- Large bundle
- Performance issues
Code Example
// Use Luxon or Day.js instead for new projects
import moment from 'moment-timezone';
const time = moment().tz('America/New_York').format();
Temporal (Polyfill)
Future Standard (Stage 3)Modern date/time API for JavaScript (proposal, requires polyfill)
Bundle Size: ~300 KB (polyfill)
Best for: Experimental projects preparing for the future
Features & Details
Key Features
- Native JavaScript API (future)
- Immutable
- Timezone-aware
- Multiple calendar systems
- Precise duration handling
- No floating point math
Pros
- Future standard
- Comprehensive
- Type-safe
- Addresses Date issues
Cons
- Not yet standard
- Large polyfill
- API still changing
- Limited tooling
Code Example
import { Temporal } from '@js-temporal/polyfill';
const now = Temporal.Now.zonedDateTimeISO('America/New_York');
const instant = now.toInstant();
📚 Learn more: JavaScript Date-Time Guide
🐍 Python
datetime (stdlib)
Built-inPython standard library for date and time manipulation
Bundle Size: N/A (built-in)
Best for: Simple datetime operations without complex timezones
Features & Details
Key Features
- Date and time classes
- Timezone support (limited)
- Timedelta arithmetic
- strftime/strptime formatting
- ISO 8601 support
Pros
- Built-in
- No dependencies
- Well documented
- Fast
Cons
- Limited timezone database
- API inconsistencies
- Need pytz for comprehensive support
Code Example
from datetime import datetime, timezone
now = datetime.now(timezone.utc)
timestamp = now.timestamp()
iso = now.isoformat()
pytz
Recommended (for older Python)Accurate timezone calculations using the IANA database
Bundle Size: N/A (Python package)
Best for: Python < 3.9 or projects requiring pytz
Features & Details
Key Features
- Full IANA timezone database
- Accurate DST handling
- Works with datetime
- Localized datetime objects
- Historical timezone data
Pros
- Comprehensive timezone support
- Industry standard
- Well tested
Cons
- Tricky API (localize vs normalize)
- Use zoneinfo in Python 3.9+
Code Example
import pytz
from datetime import datetime
tz = pytz.timezone('America/New_York')
dt = datetime.now(tz)
utc = dt.astimezone(pytz.UTC)
zoneinfo (stdlib 3.9+)
Recommended (Python 3.9+)Modern timezone support built into Python 3.9+
Bundle Size: N/A (built-in)
Best for: All new Python 3.9+ projects
Features & Details
Key Features
- IANA timezone database
- Part of standard library
- Works seamlessly with datetime
- Simpler API than pytz
- PEP 615 compliant
Pros
- Built into Python 3.9+
- Simpler than pytz
- Modern API
- No external dependencies
Cons
- Requires Python 3.9+
- May need tzdata package
Code Example
from datetime import datetime
from zoneinfo import ZoneInfo
tz = ZoneInfo('America/New_York')
dt = datetime.now(tz)
iso = dt.isoformat()
Arrow
PopularHuman-friendly datetime library for Python
Bundle Size: N/A (Python package)
Best for: Projects needing user-friendly datetime API
Features & Details
Key Features
- User-friendly API
- Timezone support
- Relative time (humanize)
- Parsing and formatting
- Range generation
- Works with datetime
Pros
- Intuitive API
- Good documentation
- Human-readable relative time
Cons
- Extra dependency
- Slower than datetime
- Overlaps with standard library
Code Example
import arrow
now = arrow.now('America/New_York')
timestamp = now.timestamp()
humanized = now.humanize() # "just now"
Pendulum
PopularPython datetime library with better timezone handling than native
Bundle Size: N/A (Python package)
Best for: Complex datetime logic and timezone handling
Features & Details
Key Features
- Drop-in replacement for datetime
- Better timezone support
- Period/Duration classes
- Human-readable differences
- Immutable
- Better DST handling
Pros
- Better than datetime
- Clean API
- Immutable
- Good timezone support
Cons
- Extra dependency
- Use zoneinfo for Python 3.9+
- Heavier than Arrow
Code Example
import pendulum
now = pendulum.now('America/New_York')
diff = now.diff_for_humans()
iso = now.to_iso8601_string()
📚 Learn more: Python Timestamps Guide
☕ Java
java.time (JSR-310)
Recommended (Java 8+)Modern date-time API introduced in Java 8
Bundle Size: N/A (built-in)
Best for: All Java 8+ applications
Features & Details
Key Features
- Immutable datetime classes
- Timezone support (ZoneId)
- Duration and Period
- Clock abstraction (testable)
- DateTimeFormatter
- Thread-safe
Pros
- Built-in Java 8+
- Thread-safe
- Immutable
- Excellent API design
Cons
- Not available in Java 7 or earlier
- Verbose
- Learning curve
Code Example
import java.time.*;
ZonedDateTime now = ZonedDateTime.now(ZoneId.of("America/New_York"));
Instant instant = now.toInstant();
long epoch = instant.getEpochSecond();
Joda-Time
Legacy (use java.time instead)Quality replacement for Java date/time classes (pre-Java 8)
Bundle Size: External JAR (~634 KB)
Best for: Legacy Java 7 applications only
Features & Details
Key Features
- Immutable datetime
- Comprehensive timezone support
- Date arithmetic
- Formatting and parsing
- Interval and Duration
Pros
- Mature
- Well documented
- Better than old Date/Calendar
Cons
- External dependency
- Use java.time for Java 8+
- No longer actively developed
Code Example
// Use java.time instead for Java 8+
import org.joda.time.*;
DateTime now = DateTime.now(DateTimeZone.forID("America/New_York"));
long millis = now.getMillis();
ThreeTen-Backport
For Java 6/7Backport of JSR-310 (java.time) to Java 6 and 7
Bundle Size: External JAR (~500 KB)
Best for: Java 6/7 projects that cannot upgrade
Features & Details
Key Features
- Same API as java.time
- Works on Java 6/7
- Immutable
- Thread-safe
- Timezone support
Pros
- java.time API on Java 6/7
- Easy migration to Java 8
- Well maintained
Cons
- External dependency
- Upgrade to Java 8+ instead
- Larger JAR size
Code Example
import org.threeten.bp.*;
ZonedDateTime now = ZonedDateTime.now(ZoneId.of("America/New_York"));
Instant instant = now.toInstant();
📚 Learn more: Java Date-Time API Guide
🐘 PHP
DateTime / DateTimeImmutable
Built-in (Recommended)PHP built-in datetime classes with timezone support
Bundle Size: N/A (built-in)
Best for: All PHP projects (use DateTimeImmutable)
Features & Details
Key Features
- Mutable (DateTime) and immutable variants
- Timezone support
- Date arithmetic
- Formatting and parsing
- DateInterval and DatePeriod
Pros
- Built-in
- No dependencies
- Good timezone support
- Immutable option
Cons
- API can be verbose
- Mutable DateTime can cause bugs
Code Example
<?php
$dt = new DateTimeImmutable('now', new DateTimeZone('America/New_York'));
$timestamp = $dt->getTimestamp();
$iso = $dt->format(DateTime::ATOM);
Carbon
Very PopularHuman-friendly extension of DateTime with many conveniences
Bundle Size: Composer package
Best for: Laravel apps and projects needing human-friendly API
Features & Details
Key Features
- Extends DateTime/DateTimeImmutable
- Fluent API
- Human-readable differences
- Extensive helpers
- Localization support
- Used by Laravel
Pros
- Extremely user-friendly
- Extensive features
- Great documentation
- Laravel integration
Cons
- External dependency
- Can be overkill
- Performance overhead
Code Example
<?php
use Carbon\Carbon;
$now = Carbon::now('America/New_York');
$timestamp = $now->timestamp;
$humanized = $now->diffForHumans(); // "just now"
Chronos
PopularCarbon alternative focused on immutability and consistency
Bundle Size: Composer package
Best for: Projects prioritizing immutability over features
Features & Details
Key Features
- Immutable by default
- Carbon-like API
- No extra dependencies
- Lightweight
- CakePHP integration
Pros
- Immutable
- Lightweight
- Carbon-compatible API
- No ext dependencies
Cons
- Smaller community than Carbon
- Less features than Carbon
Code Example
<?php
use Cake\Chronos\Chronos;
$now = Chronos::now('America/New_York');
$timestamp = $now->timestamp;
$modified = $now->addDays(5); // Returns new instance
📚 Learn more: PHP DateTime Best Practices
💎 Ruby
Time (stdlib)
Built-inRuby built-in Time class with timezone support
Bundle Size: N/A (built-in)
Best for: Simple Ruby scripts and small projects
Features & Details
Key Features
- Basic timezone support
- Unix timestamp conversion
- Time arithmetic
- Parsing and formatting
- UTC and local time
Pros
- Built-in
- Fast
- No dependencies
- Simple API
Cons
- Limited timezone support
- Need ActiveSupport for comprehensive features
Code Example
require 'time'
now = Time.now
timestamp = now.to_i
iso = now.iso8601
ActiveSupport::TimeWithZone
Recommended (Rails)Rails timezone-aware time implementation
Bundle Size: Part of Rails / activesupport gem
Best for: All Rails applications
Features & Details
Key Features
- Full timezone support
- Timezone-aware arithmetic
- Time zones configuration
- Human-readable helpers
- Works with Time and DateTime
Pros
- Excellent timezone support
- Rails integration
- User-friendly
- Well documented
Cons
- Requires ActiveSupport
- Heavier than stdlib
- Rails-specific
Code Example
require 'active_support/time'
Time.zone = 'America/New_York'
now = Time.zone.now
timestamp = now.to_i
humanized = now.to_s(:long)
TZInfo
RecommendedTimezone library providing support for IANA timezone database
Bundle Size: Gem (~100 KB + timezone data)
Best for: Non-Rails Ruby projects needing timezone support
Features & Details
Key Features
- Full IANA timezone database
- Timezone conversions
- DST handling
- Historical timezone data
- Used by ActiveSupport
Pros
- Comprehensive timezone support
- Well maintained
- Accurate DST handling
Cons
- Requires gem
- Lower-level API
- Usually used via ActiveSupport
Code Example
require 'tzinfo'
tz = TZInfo::Timezone.get('America/New_York')
now = tz.now
local_time = tz.to_local(Time.now.utc)
📚 Learn more: Ruby Time and DateTime Guide
🔷 Go
time (stdlib)
RecommendedGo standard library time package with excellent timezone support
Bundle Size: N/A (built-in)
Best for: All Go applications
Features & Details
Key Features
- time.Time with timezone
- Duration arithmetic
- Timezone database (IANA)
- Parsing and formatting
- Monotonic clock support
- Timer and Ticker
Pros
- Built-in
- Excellent design
- Timezone support included
- High performance
Cons
- Format strings use reference time (can be confusing)
- Minimal helpers
Code Example
package main
import "time"
func main() {
loc, _ := time.LoadLocation("America/New_York")
now := time.Now().In(loc)
unix := now.Unix()
iso := now.Format(time.RFC3339)
}
now
PopularTime toolkit for Go with useful helpers
Bundle Size: Go module
Best for: Projects needing convenient time period helpers
Features & Details
Key Features
- Beginning/end of time periods
- Parse relative times
- Monday/Sunday helpers
- Quarter calculations
- Works with time.Time
Pros
- Convenient helpers
- Small and focused
- Active development
Cons
- External dependency
- Not comprehensive
- Use stdlib for most cases
Code Example
package main
import "github.com/jinzhu/now"
func main() {
beginning := now.BeginningOfMonth()
end := now.EndOfDay()
monday := now.Monday()
}
carbon (Go)
PopularCarbon-like API for Go (inspired by PHP Carbon)
Bundle Size: Go module
Best for: Projects needing PHP Carbon-like API in Go
Features & Details
Key Features
- Fluent API
- Human-readable differences
- Extensive helpers
- Timezone support
- Localization
Pros
- User-friendly API
- Many helpers
- Good documentation
Cons
- External dependency
- Overkill for simple cases
- stdlib usually sufficient
Code Example
package main
import "github.com/golang-module/carbon/v2"
func main() {
now := carbon.Now("America/New_York")
timestamp := now.Timestamp()
humanized := now.DiffForHumans()
}
📚 Learn more: Go time Package Tutorial
🔷 C# / .NET
DateTime / DateTimeOffset
Built-in (Recommended).NET built-in datetime types with timezone support
Bundle Size: N/A (built-in)
Best for: All .NET applications (prefer DateTimeOffset)
Features & Details
Key Features
- DateTime (local or UTC)
- DateTimeOffset (timezone-aware)
- TimeSpan arithmetic
- Timezone conversions
- Formatting and parsing
- TimeZoneInfo class
Pros
- Built-in
- Type-safe
- Good performance
- DateTimeOffset is timezone-aware
Cons
- DateTime timezone semantics confusing
- Prefer DateTimeOffset
Code Example
using System;
var now = DateTimeOffset.Now;
var utc = DateTimeOffset.UtcNow;
var timestamp = now.ToUnixTimeSeconds();
var iso = now.ToString("o");
NodaTime
Recommended for Complex Use CasesBetter date and time API for .NET (by Jon Skeet)
Bundle Size: NuGet package
Best for: Complex datetime logic and financial systems
Features & Details
Key Features
- Better API design than BCL
- Comprehensive timezone support
- Type-safe (Instant, LocalDateTime, ZonedDateTime)
- Period and Duration
- Calendar systems
- Excellent documentation
Pros
- Better API than BCL
- Type safety
- Excellent timezone support
- Well documented
Cons
- External dependency
- Learning curve
- Overkill for simple cases
Code Example
using NodaTime;
var zone = DateTimeZoneProviders.Tzdb["America/New_York"];
var now = SystemClock.Instance.GetCurrentInstant().InZone(zone);
var timestamp = now.ToInstant().ToUnixTimeSeconds();
📚 Learn more: Browse all language guides
🦀 Rust
chrono
RecommendedDate and time library for Rust
Bundle Size: Cargo crate
Best for: All Rust projects needing datetime
Features & Details
Key Features
- DateTime with timezone
- Duration arithmetic
- Timezone support
- Formatting and parsing
- Serde support
- Type-safe
Pros
- De facto standard
- Comprehensive
- Serde integration
- Type-safe
Cons
- Complex API for simple tasks
- Larger dependency
- Maintenance concerns
Code Example
use chrono::{DateTime, Utc, TimeZone};
let now: DateTime<Utc> = Utc::now();
let timestamp = now.timestamp();
let iso = now.to_rfc3339();
time
AlternativeModern date and time library for Rust
Bundle Size: Cargo crate
Best for: New Rust projects wanting modern API
Features & Details
Key Features
- Type-safe
- Formatting macros
- Serde support
- Smaller than chrono
- Better error handling
Pros
- Modern API
- Smaller
- Good error handling
- Active development
Cons
- Smaller ecosystem
- Less mature
- API changes
Code Example
use time::OffsetDateTime;
let now = OffsetDateTime::now_utc();
let timestamp = now.unix_timestamp();
let iso = now.to_string();
📚 Learn more: Browse all language guides
Selection Guide: Common Questions
Which JavaScript library should I use?
For most projects: Luxon (best timezone support) or Day.js (smallest bundle). Use date-fns if you prefer functional programming. Avoid Moment.js for new projects.
Do I need a library at all?
For simple UTC timestamps and formatting, native Date might be enough. Add a library when you need: accurate timezone conversions, complex date arithmetic, or localization.
What about Python 3.9+ projects?
Use built-in datetime + zoneinfo. No external dependencies needed. For older Python, use pytz.
Should I use Carbon in PHP?
Yes for Laravel projects (it's included). For pure PHP, built-in DateTimeImmutable is often sufficient. Add Carbon if you need human-friendly helpers.
Do I need NodaTime in .NET?
Not usually. DateTimeOffset handles most cases. Use NodaTime for: financial systems, complex timezone logic, or when you need better API design.
Bundle size vs features trade-off?
Small projects: Native APIs or minimal libraries (Day.js, native datetime). Large projects: Full-featured libraries (Luxon, Carbon) worth the extra KB.
Additional Resources
- Ultimate List of Timestamp Tools - Compare web tools, libraries, and CLIs
- Timezone API Comparison - Compare timezone and time synchronization APIs
- Timezone Conversion Best Practices - Avoid common timezone mistakes
- Testing Time-Dependent Code - Mock time in tests across all languages
- Try Timestamp Generator - Free web-based timestamp converter