datr
v4.0.0
Published
Dependency-free utility for generating YYYYMMDDHHMMSS timestamps. Perfect for logs, file naming, and automated workflows.
Maintainers
Readme
🕘 DATR
Dates should be sortable and human-readable at the same time. Unix timestamps are sortable but unreadable. Most date strings are readable but not sortable. YYYYMMDDHHMMSSms is both - common among developers, yet never formally standardized.
Useful for console logging, generating IDs, naming files, and more.
Module Installation
npm i datrpnpm add datrbun i datrdeno add npm:datrModule Usage
import datr from 'datr';
console.log(typeof datr());
// string
console.log(datr());
// 20260508
console.log(datr({ precision: 'seconds' }));
// 20260508104700
console.log(datr({ precision: 'ms', separator: '-' }));
// 20260508-104700-001
console.log(datr({ date: '2024-06-15', precision: 'seconds' }));
// 20240615000000Options
The datr function accepts an optional options object:
| Option | Type | Default | Description |
|---|---|---|---|
| precision | 'day' \| 'seconds' \| 'ms' | 'day' | Smallest unit in the output. |
| separator | string | '' | String inserted between blocks. |
| date | Date \| string \| number | new Date() | Date to format (Date object, ISO string, or timestamp). |
CLI installation
npm i -g datrpnpm add -g datrbun i -g datrdeno i -g datrCLI usage
datr
# 20260508
datr --precision seconds
# 20260508104700
datr --precision ms --separator -
# 20260508-104700-001
datr --date 2024-06-15 --precision seconds
# 20240615000000
datr --version
# 4.0.0
datr --help
# Usage: datr [options] ...All options also support short flags: -p, -s, -d, -v, and -h.
datr -d "$(date)" -p ms -s -
# 20260508-104700-222CLI usage without installation
npx datrpnpm dlx datrbunx datrdeno run npm:datrMigrating from v3
The API has changed from positional arguments to a single options object.
| v3 (Positional) | v4 (Object) |
|---|---|
| datr() | datr() |
| datr(1) | datr({ precision: 'seconds' }) |
| datr(2) | datr({ precision: 'ms' }) |
| datr(2, '-') | datr({ precision: 'ms', separator: '-' }) |
