epochify
v1.0.12
Published
🕒 A modern and lightweight date-time utility library for Node.js and browsers.
Maintainers
Readme
Epochify
Overview
Epochify is a modern and lightweight date-time utility library for Node.js and browsers. It helps you handle timestamps, format dates, and calculate time differences in a clean and efficient way.
Quick Example
import epochify from "epochify";
console.log(epochify.format(Date.now(), "YYYY-MM-DD HH:mm:ss"));
Features
- Lightweight (under 20kb)
- Works in both Node.js and browsers
- Zero dependencies
- TypeScript support included
- Simple and clean API design
Installation
npm install epochify
# or
yarn add epochifyUsage
CommonJS Example
const epochify = require("epochify");
console.log(epochify.getFullDateTime());ES Module Example
import epochify from "epochify";
console.log(epochify.getFullDateTime());TypeScript Example
import type { FullDateTime } from "epochify";
const dt: FullDateTime = epochify.getFullDateTime();
console.log(dt);API Reference
Below are all available methods in Epochify, with explanations and examples.
getRawDateTime()
Returns an object containing the current local date and time values.
epochify.getRawDateTime();
/* {
date: { day: 4, month: 11, year: 2025 },
time: { hours: 15, minutes: 16, seconds: 00 }
} */getFormattedDate()
Returns today's date in DD-MM-YYYY format, with each part separately.
epochify.getFormattedDate();
// { formatted: "04-11-2025", day: "04", month: "11", year: 2025 }getFormattedTime()
Returns current time in HH:MM:SS format and components.
epochify.getFormattedTime();
// { formatted: "15:16:00", hours: "15", minutes: "16", seconds: "00" }getReadableDate()
Returns date in a human-readable format.
epochify.getReadableDate(); // "Tue Nov 04 2025"getISODateTime()
Returns the current date/time in ISO 8601 format.
epochify.getISODateTime();
// "2025-11-04T09:46:00.000Z"getTimestamp()
Returns current timestamp in milliseconds.
epochify.getTimestamp();
// 1762355760000getUnixTimestamp()
Returns current Unix timestamp in seconds.
epochify.getUnixTimestamp();
// 1762355760getFullDateTime()
Returns an object with all major date & time formats.
epochify.getFullDateTime();
/*
{
date: { formatted: "04-11-2025", day: "04", month: "11", year: 2025 },
time: { formatted: "15:16:00", hours: "15", minutes: "16", seconds: "00" },
iso: "2025-11-04T09:46:00.000Z",
unix: 1762355760,
timestamp: 1762355760000,
readable: "Tue Nov 04 2025"
}
*/format(time, formatStyle)
Formats a timestamp/date to a custom string.
epochify.format(Date.now(), "YYYY-MM-DD weekDay HH:mm:ss");
// "2025-11-04 Tue 15:16:00"
epochify.format("2025-01-01T10:30:00Z", "DD/MM/YYYY HH:mm:ss ap");
// "01/01/2025 10:30:00 AM"diff(orgDate, comDate, unit)
Finds the difference between two dates in any standard unit.
epochify.diff("2025-11-04", "2025-10-31", "days");
// 4
epochify.diff(1762355760000, 1761923760000, "hours");
// 120getMonthsCount(orgDate, comDate)
Get absolute month difference between two dates.
epochify.getMonthsCount("2025-09-01", "2024-05-15");
// 16isLeap(year)
Checks if a year is leap.
epochify.isLeap(2024); // true
epochify.isLeap(2025); // falseTypeScript Types
Main interfaces included for TypeScript users:
interface DateObject {
date: { day: number; month: number; year: number; };
time: { hours: number; minutes: number; seconds: number; };
}
interface FormattedDate {
formatted: string;
day: string;
month: string;
year: number;
}
interface FormattedTime {
formatted: string;
hours: string;
minutes: string;
seconds: string;
}
interface FullDateTime {
date: FormattedDate;
time: FormattedTime;
iso: string;
unix: number;
timestamp: number;
readable: string;
}Hidden Power Functions (Most Underrated)
These functions aren’t flashy but make Epochify powerful under the hood:
getRawDateTime()
Returns a structured breakdown of the current date and time.
epochify.getRawDateTime();
// → { date: { day: 4, month: 11, year: 2025 }, time: { hours: 22, minutes: 15, seconds: 30 } }Perfect for low‑level time processing or custom format logic.
getStartOf(unit)
Quickly fetch the start of the current day, month, or year.
epochify.getStartOf('day');
// → 1730678400000 (midnight timestamp)Useful for analytics, resets, or daily cron comparisons.
add(timestamp, value, unit)
Add or subtract any time value dynamically.
epochify.add(Date.now(), 7, 'days');
// → adds 7 days to the current timePerfect for scheduling, reminders, or future date calculations.
Advanced Usage Tips
- Accepts date inputs as string, number, or JS Date object.
- Safe for frontend and backend.
- Use
.defaultfor ESM/CJS interop if needed.
Why Use Epochify?
- No dependencies or bloat
- Consistent and simple API
- Replace heavier libraries easily
- Fast, reliable, and TypeScript ready
License
MIT © 2025 Ayush
