ChronosChronos

From Now Plugin

From Now Plugin — Chronos Plugin Documentation.

About From Now Plugin

From now plugin is a plugin that adds from now related functionalities to Chronos.

Import & Usage

Import

To use the From Now Plugin, import it first:

import { Chronos, chronos } from "chronos-date";
import { fromNowPlugin } from 'chronos-date/plugins/fromNowPlugin';

Register

Now you can use the plugin's methods:

// Register the plugin globally
Chronos.use(fromNowPlugin);
// or
chronos.use(fromNowPlugin);
// or
Chronos.register(fromNowPlugin);
// or
chronos.register(fromNowPlugin);

Usage

Example usage of the fromNowPlugin:

const c = new Chronos('2024-08-05T00:00:00.0+06:00');

const fromNow = c.fromNow('hour');

console.log(fromNow);

Example Usage

playground.ts

Overview

The fromNowPlugin adds from now functionalities to Chronos, enabling:

  • Calculating the elapsed time difference between two dates.

Methods Added by the Plugin

Note

All these methods are provided by fromNowPlugin. You must register it using Chronos.use(fromNowPlugin) before calling them. Once registered, all Chronos instances will have access to these methods.

MethodDescriptionReturns
fromNowCalculates the elapsed time difference between two dates.string

API Reference

fromNow()

Info

  • This method calculates the elapsed time difference (excludes the end day), consistent with libraries like Day.js and Luxon.
  • If you need an inclusive calendar-style difference (counting both start and end days), adjust one day manually before calling fromNow().
  • The smallest unit included can be customized via the level parameter (from 'year' to 'millisecond').
  • Returns "0 <unit>" if no time difference is detected at the requested precision.

Signature

fromNow(level?: FromNowUnit, withSuffixPrefix?: boolean, time?: ChronosInput): string

Parameters

  • level: Smallest unit to include (default: 'second')
  • withSuffixPrefix: Include "ago" or "in" depending on the time direction (default: true)
  • time: Optional comparison time (string, number, Date, or Chronos instance). Defaults to now.

Return Type

string - Human-readable duration

Type Definition

/** Name of time unit from `'year'` to `'millisecond'`, excluding `'week'` */
type FromNowUnit = "year" | "month" | "day" | "hour" | "minute" | "second" | "millisecond";

Example

import { fromNowPlugin } from 'chronos-date/plugins/fromNowPlugin';

Chronos.use(fromNowPlugin);

new Chronos().fromNow(); // "0 second ago"
new Chronos().add(3, 'hours').fromNow(); // "in 3 hours"
new Chronos().subtract(2, 'days').fromNow(); // "2 days ago"

new Chronos('2020-03-16').fromNow('day', false, '2025-10-01'); 
// "5 years 6 months 15 days" (exclusive of end day)

new Chronos('2020-03-16').subtract(1, 'day').fromNow('day', false, '2025-10-01'); 
// "5 years 6 months 16 days" (inclusive of end day)

Last updated: Wed, Jun 24, 2026 09:04:13AM (UTC)

On this page