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

formatDistanceStrict

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

§Type Parameters

§
DateType extends Date
[src]

§Parameters

§
date: DateType | number | string
[src]
  • The date
§
baseDate: DateType | number | string
[src]
  • The date to compare with
§
  • An object with options

§Return Type

§
string
[src]

The distance in words