How to Do Date Formatting with Day.js on Claude Code
To do date formatting with Day.js on Claude Code, open a session, install the library with npm install dayjs, then ask Claude to scaffold the formatting logic you need. Claude Code handles the import, plugin registration, and token syntax automatically, so you stay focused on the output you want rather than digging through docs. Day.js is only 2 KB (gzipped), making it a fast, drop-in alternative to Moment.js for most projects.
- Who it is for: JavaScript and TypeScript developers who need readable, locale-aware date strings without bloated dependencies.
- Key trade-off: Day.js is immutable and chainable but relies on opt-in plugins for advanced features like UTC, timezone, and relative time, so Claude needs to know which plugins to register.
- Hard data: Day.js bundles at ~2 KB gzipped vs. ~72 KB for Moment.js; supports 138+ locales; over 46 million weekly npm downloads.
What is Day.js and why use it with Claude Code?
Day.js is a minimalist JavaScript library that parses, validates, manipulates, and formats dates using a Moment.js-compatible API. Because the API surface is familiar and well-documented, Claude Code can generate accurate, working code on the first attempt with a clear prompt, meaning fewer back-and-forth iterations and less time context-switching away from your editor.
Claude Code is Anthropic's AI-powered CLI that runs directly in your terminal. It reads your project files, understands your stack, and writes code in context, so when you ask it to "add Day.js date formatting to this utility file," it already knows your imports, naming conventions, and TypeScript types.
How to install Day.js inside a Claude Code session
Before prompting Claude to write formatting code, add Day.js to your project. You can either run the install command yourself or ask Claude to do it:
# ask Claude Code directly
> Install dayjs as a dependency and confirm the version added to package.json
Claude will run npm install dayjs (or the package manager your project uses), verify the install, and confirm the version in package.json. If you prefer to install manually first:
npm install dayjs
# or
yarn add dayjs
# or
pnpm add dayjs
How to prompt Claude Code for basic date formatting
Once Day.js is installed, describe the output format you want in plain English. Claude Code translates that into the correct Day.js format tokens automatically.
Example prompt
> Using dayjs, format today's date as "Monday, 09 May 2026" and export a reusable formatDate helper in src/utils/date.ts
What Claude generates
import dayjs from 'dayjs'
export function formatDate(date?: string | Date): string {
return dayjs(date).format('dddd, DD MMMM YYYY')
}
Common Day.js format tokens Claude Code works with out of the box:
YYYY-MM-DD: ISO 8601 (e.g., 2026-05-09)DD/MM/YYYY: UK / AU style (e.g., 09/05/2026)MMM D, YYYY: Short month (e.g., May 9, 2026)hh:mm A: 12-hour clock with AM/PM (e.g., 02:30 PM)HH:mm:ss: 24-hour clock with seconds (e.g., 14:30:00)dddd, DD MMMM YYYY: Full weekday and month (e.g., Saturday, 09 May 2026)
How to use Day.js plugins with Claude Code
Day.js keeps its core tiny by putting advanced features into opt-in plugins. Tell Claude which behaviour you need and it will import and extend the correct plugin automatically.
UTC and timezone formatting
> Format the timestamp "2026-05-09T14:30:00Z" in UTC and also in "America/New_York" timezone using dayjs
Claude registers the utc and timezone plugins from dayjs/plugin/ and sets up the dayjs-plugin-timezone dependency if needed, per the Day.js timezone plugin docs.
Relative time ("2 hours ago")
> Add a timeAgo helper that returns relative time strings like "3 days ago" using dayjs
Claude imports the relativeTime plugin and calls .fromNow():
import dayjs from 'dayjs'
import relativeTime from 'dayjs/plugin/relativeTime'
dayjs.extend(relativeTime)
export const timeAgo = (date: string | Date) => dayjs(date).fromNow()
Locale-aware formatting
> Format dates in French using dayjs locale support
Claude imports the locale file (dayjs/locale/fr) and applies .locale('fr') before formatting, using the Day.js i18n API.
Using Claude Code's /doc and search commands to explore the Day.js API
Claude Code includes several built-in slash commands that help you work faster without leaving the terminal:
- Type
/in your session to browse available commands. - Use
shift+tabto accept partial suggestions or tab through options. - Ask Claude to search its context for existing date utilities before adding new ones, avoiding duplicate code:
> Search this repo for any existing date formatting helpers before adding a new one
If you need to check which version of Day.js is installed or whether a plugin is already registered, just ask: > What version of dayjs is in this project and which plugins are currently extended?
Staying in flow while working on date utilities
One underappreciated cost of working with Claude Code is losing track of your usage limit mid-task. If you are 80% through refactoring a date utility module and Claude Code hits your hourly cap, you face a 5-hour lockout at the worst possible moment, right before you can finish the PR.
Usagebar sits in your macOS menu bar and shows your Claude Code usage in real time. It fires smart alerts at 50%, 75%, and 90% so you can wrap up a critical task before the limit hits, rather than getting cut off mid-session. Credentials are stored securely in macOS Keychain, and the app shows exactly when your usage window resets, so you never have to guess.
Pricing is pay-what-you-want, with a free tier available for students. Get Usagebar and keep date formatting sessions (and every other session) from being cut short.
For a deeper look at managing limits, see:
- How to check your Claude Code usage limits
- How to reduce Claude Code token usage
- How many messages per hour does Claude Code allow?
- Does Claude Code usage affect Pro limits?
Key takeaways
- Install Day.js with
npm install dayjsbefore or during your Claude Code session. - Describe your desired output in plain English. Claude Code resolves the correct format tokens.
- Name the plugin you need (UTC, timezone, relativeTime, locale) and Claude imports and extends it automatically.
- Use Claude's built-in slash commands to search your repo for duplicate helpers before adding new ones.
- Monitor your usage with Usagebar to avoid hitting your limit mid-task during longer refactors.
Sources
Track Your Claude Code Usage
Never hit your usage limits unexpectedly. Usagebar lives in your menu bar and shows your 5-hour and weekly limits at a glance.
Get Usagebar