⏰ Lightweight and elegant date library

Understand Day.js at a glance
with a rich single-page introduction

Day.js is a minimalist JavaScript library for parsing, validating, manipulating, and formatting dates. It offers a developer experience that feels familiar to Moment.js, while staying lighter, cleaner, immutable by default, and extensible through focused plugins.

Moment-style API Immutable Plugin-based TypeScript-friendly

Why do many frontend teams choose it?

Date handling looks simple at first, but real products quickly need formatting rules, locale support, parsing logic, timezone conversion, and readable date math. Day.js lets you start small and add only the features you actually need.

Lightweight Designed with bundle size in mind
Easy to read Chainable and expressive API
Safer state Immutable operations by default
Flexible Extend features with plugins
quick-start.js
import dayjs from '@hamzaka/dayjs'

const today = dayjs()
const result = today
  .startOf('month')
  .add(1, 'day')
  .format('YYYY-MM-DD HH:mm:ss')

// clean, readable, and chainable
console.log(result)
Why Day.js

A small library with practical real-world value

Day.js is not just β€œa tiny date library.” It is built around the date workflows that most applications use every day, while keeping the architecture modular enough to stay lean in production.

✨

Familiar API

Developers who have used Moment.js can adapt quickly. The chain-based API is intuitive, concise, and easy to scan inside business logic and UI code.

🧊

Immutability

Most operations return a new instance instead of mutating the original date object. That makes state handling more predictable and helps reduce side effects in complex applications.

🌍

Localization

Day.js supports locale-aware formatting and human-readable date output. You can load only the locales your project needs instead of carrying unnecessary language data.

Core Features

Even the basics cover a lot of practical use cases

Most date libraries are used for a similar set of tasks: parsing input, formatting output, comparing values, adding and subtracting time, and aligning dates to boundaries such as the start of a month or week. Day.js provides these tasks through a consistent API.

Common usage scenarios

  • Parse a date string from an API and display it in a user-friendly format
  • Render timestamps like β€œ3 minutes ago,” β€œyesterday,” or a full date
  • Calculate expiration times, booking windows, or deadline offsets
  • Find the start of a week, month, quarter, or year
  • Handle UTC values and convert them to user-facing timezones
format-parse-manipulate.js
import dayjs from '@hamzaka/dayjs'

// parse
const d1 = dayjs('2026-04-02')

// format
console.log(d1.format('YYYY MMM DD'))

// manipulate
const d2 = d1.add(7, 'day').subtract(2, 'hour')

// compare
console.log(d2.isAfter(d1))

// boundary helpers
console.log(d1.startOf('month').format('YYYY-MM-DD'))
Examples

Useful code snippets you can adapt right away

One of Day.js’s biggest strengths is how compact and readable the syntax feels. The examples below are meant to serve as a practical starting point for real projects.

01

Install and use the basics

Once installed, you can create an instance and format it immediately. That is enough to power many UI date displays.

installation.jsbasic
npm install @hamzaka/dayjs

import dayjs from '@hamzaka/dayjs'

console.log(dayjs().format())
02

Parse custom input formats

If input strings follow a known format, the CustomParseFormat plugin makes it easier to parse them in a controlled way.

custom-parse.jsplugin
import dayjs from '@hamzaka/dayjs'
import customParseFormat from '@hamzaka/dayjs/plugin/customParseFormat'

dayjs.extend(customParseFormat)

const value = dayjs('12-25-1995', 'MM-DD-YYYY')
console.log(value.format('YYYY/MM/DD'))
03

Work with timezones

With the UTC and Timezone plugins, it becomes much easier to manage multi-region products and convert server times for end users.

timezone.jsadvanced
import dayjs from '@hamzaka/dayjs'
import utc from '@hamzaka/dayjs/plugin/utc'
import timezone from '@hamzaka/dayjs/plugin/timezone'

dayjs.extend(utc)
dayjs.extend(timezone)

const toronto = dayjs.tz('2013-11-18 11:55:20', 'America/Toronto')
console.log(toronto.format())
Plugin System

Keep the core small and extend only what you need

Day.js does not try to put every feature into the core package. Instead, it uses plugins to add capabilities when your application needs them. This makes it easier to stay efficient while still supporting advanced use cases.

🧩

AdvancedFormat

Use richer formatting tokens when the built-in options are not enough for your design or reporting requirements.

πŸ•“

RelativeTime

Great for activity feeds, messages, notifications, and any UI that needs phrases like β€œ5 minutes ago.”

🌐

UTC / Timezone

Essential when backend systems store UTC values and your interface needs to present the correct local time.

Best Fit

Where Day.js shines most

Great choice when

  • You need frequent date display and date math in a web application
  • Your team likes the feel of Moment-style chaining
  • You care about keeping frontend bundles lean
  • You want a fast, practical date library for TypeScript projects

Things to keep in mind

  • Some advanced features require plugins rather than the core package alone
  • Timezone and locale strategy should be planned consistently across the project
  • If your inputs vary widely, parsing rules should be defined clearly
FAQ

Frequently asked questions

Q. Is Day.js a replacement for Moment.js?

In many projects, yes. It keeps a familiar developer experience while offering a lighter footprint and an immutable design.

Q. Are all features included by default?

No. The core stays intentionally small, and features such as custom parsing, UTC, and timezone support are added through plugins.

Q. Can I use it easily with TypeScript?

Yes. Day.js works well in TypeScript environments and is commonly used in modern frontend stacks.