How to use the formatDistanceToNowStrict function from date-fns

Find comprehensive JavaScript date-fns.formatDistanceToNowStrict code examples handpicked from public code repositorys.

175
176
177
178
179
180
181
182
183
184

  return result
}

function formatDistanceAbbr (date) {
  return formatDistanceToNowStrict(date, {
    locale: {
      ...locale,
      formatDistance
    }
fork icon35
star icon55
watch icon9

45
46
47
48
49
50
51
52
53
54
forum: {
    ...forum.toJSON(),
    threads: threads.map(t => ({
        ...t.toJSON(),
        createdAtText: formatDistanceToNowStrict(new Date(t.createdAt), { addSuffix: true }),
        updatedAtText: formatDistanceToNowStrict(new Date(t.updatedAt), { addSuffix: true }),
    })),
    count: threads.length,
    updatedAtText: formatDistanceToNowStrict(new Date(forum.updatedAt), { addSuffix: true })
}
fork icon3
star icon1
watch icon0

+ 5 other calls in file

8
9
10
11
12
13
14
15
16
17

const due = dateFns.parseISO(dueDate);

const isOverDue = dateFns.isPast(due);

const distanceFromToday = dateFns.formatDistanceToNowStrict(due, {
  unit: 'day',
});

if (isOverDue) {
fork icon0
star icon0
watch icon0

32
33
34
35
36
37
38
39
40
41

  // find the value of h1
  const text = await page.$eval('h1', el => el.innerText);
  await browser.close();

  const distance = formatDistanceToNowStrict(new Date(2022, 9, 3), { unit: 'day', roundingMethod: 'ceil' });

  return `${text}
  
*${distance}* days left`;
fork icon0
star icon0
watch icon3

Other functions in date-fns

Sorted by popularity

function icon

date-fns.format is the most popular function in date-fns (3838 examples)