Hi there! Are you looking for the official Deno documentation? Try docs.deno.com for all your Deno learning needs.

formatDistanceToNowStrict

import { formatDistanceToNowStrict } from "https://esm.sh/v135/date-fns@3.6.0/index.d.mts";
@example
// If today is 1 January 2015, what is the distance to 2 July 2014?
const result = formatDistanceToNowStrict(
  new Date(2014, 6, 2)
)
//=> '6 months'
@example
// If now is 1 January 2015 00:00:00,
// what is the distance to 1 January 2015 00:00:15, including seconds?
const result = formatDistanceToNowStrict(
  new Date(2015, 0, 1, 0, 0, 15)
)
//=> '15 seconds'
@example
// If today is 1 January 2015,
// what is the distance to 1 January 2016, with a suffix?
const result = formatDistanceToNowStrict(
  new Date(2016, 0, 1),
  {addSuffix: true}
)
//=> 'in 1 year'
@example
// If today is 28 January 2015,
// what is the distance to 1 January 2015, in months, rounded up??
const result = formatDistanceToNowStrict(new Date(2015, 0, 1), {
  unit: 'month',
  roundingMethod: 'ceil'
})
//=> '1 month'
@example
// If today is 1 January 2015,
// what is the distance to 1 January 2016 in Esperanto?
const eoLocale = require('date-fns/locale/eo')
const result = formatDistanceToNowStrict(
  new Date(2016, 0, 1),
  {locale: eoLocale}
)
//=> '1 jaro'
function formatDistanceToNowStrict<DateType extends Date>(date: DateType | number | string, options?: FormatDistanceToNowStrictOptions): string;
§
formatDistanceToNowStrict<DateType extends Date>(date: DateType | number | string, options?: FormatDistanceToNowStrictOptions): string
[src]

§Type Parameters

§
DateType extends Date
[src]

§Parameters

§
date: DateType | number | string
[src]
  • The given date
§
  • An object with options.

§Return Type

§
string
[src]

The distance in words