Registry / productivity / unix-date-formatter

unix-date-formatter

JSON →
library1.2.8jsnpmunverified

A JavaScript/TypeScript library for formatting Unix timestamps and date strings into human-readable relative and locale-aware formats. Version 1.2.8 is current, with moderate release cadence. Key differentiators: supports relative time like 'About 2 days ago', locale-aware date/time formatting via Intl.DateTimeFormat, and includes both a function (unixFormatter) and a class (DateFormatter) for different use cases. Works in Node.js and browsers, with built-in TypeScript declarations. Alternative to libraries like moment.js and date-fns but more lightweight and focused on Unix timestamp formatting.

npm install unix-date-formatter
INSTALL
IMPORT
SIG · UNIX-DATE-FORMATTE
U
unix-date-formatter
productivityjavascriptv1.2.8
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

unixFormatter
import { unixFormatter } from 'unix-date-formatter/unix'
import unixFormatter from 'unix-date-formatter'
unixFormatter is exported from a subpath '/unix'. Default import does not work; must use named import from the correct module path.
DateFormatter
import { DateFormatter } from 'unix-date-formatter/date'
import { DateFormatter } from 'unix-date-formatter'
DateFormatter is exported from a subpath '/date'. The main package export does not include DateFormatter.
require('unix-date-formatter/unix')
const { unixFormatter } = require('unix-date-formatter/unix');
const unixFormatter = require('unix-date-formatter').unixFormatter
CommonJS require must use the same subpath. The main entry does not re-export unixFormatter.

Shows both library functions: relative time formatting and locale-aware date/time formatting.

import { unixFormatter } from 'unix-date-formatter/unix'; import { DateFormatter } from 'unix-date-formatter/date'; // unixFormatter: relative time from now const unixTimestamp = 1675135145; // seconds console.log(unixFormatter(unixTimestamp)); // e.g., "About 2 days ago" // DateFormatter: locale-aware formatting const df = new DateFormatter('2024-03-11T01:31:29.938Z'); const formatted = df.formatDateAndTime('Australia/Sydney', 'en-AU'); console.log(formatted); // e.g., "11 March 2024 at 12:31:29 PM AEDT" console.log(df.formatDate()); // "11 March 2024"
Debug
Known issues
gotchaunixFormatter expects timestamp in seconds (not milliseconds). Passing milliseconds produces incorrect relative times.
fix
Ensure the timestamp is in seconds. If you have milliseconds, divide by 1000 before passing.
affects: >=0.0.0
gotchaImport paths are subpath ('unix-date-formatter/unix' and 'unix-date-formatter/date'), not the package root.
fix
Use the correct subpath imports as shown in documentation. Avoid importing from the root.
affects: >=1.0.0
gotchaDateFormatter constructor expects an ISO 8601 string, not a Unix timestamp.
fix
Pass a date string (e.g., '2024-03-11T01:31:29.938Z') to DateFormatter, not a Unix number.
affects: >=0.0.0
Errors
Common errors & fixes
Cannot find module 'unix-date-formatter' or its corresponding type declarations.
Importing from the wrong default path instead of the subpath.
fix
Change import to import { unixFormatter } from 'unix-date-formatter/unix';
unixFormatter gave 'About 55 years ago' instead of expected relative time.
Passed a timestamp in milliseconds (e.g., 1675135145000) instead of seconds.
fix
Convert milliseconds to seconds by dividing by 1000: unixFormatter(timestamp / 1000)
Upgrade
Version history
1.2.8latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
21 hits · last 30 days
node
20
OpenAI (training)
1
Resources
unix-date-formatter — npm install unix-date-formatter · libregistry