How to use the formatDistance function from date-fns

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

40
41
42
43
44
45
46
47
48
49
},
isBefore(date, compare) {
  return isBefore(date, parseISO(compare))
},
dur(t1, t2) {
  return formatDistance(t1, t2)
},
format(val, type = "EEEE, MMM do h:mma") {
  return format(val, type)
},
fork icon0
star icon0
watch icon0

+ 47 other calls in file

131
132
133
134
135
136
137
138
139
140
discordNick: discordMember ? discordMember.nickname : null,
isActive,
isPassive,
memberSinceInMonths: differenceInMonths(referenceDate, joinDate),
memberSinceInYears: differenceInYears(referenceDate, joinDate),
relativeMemberTime: formatDistance(joinDate, referenceDate, { locale: de }),
membershipNoEqualsAge: parseInt(member.membershipNumber) === birthdayAge,
membershipNoEqualsBirthDate: referenceDate.getDate() === birthdayAge,
membershipNoEqualsBirthMonth: referenceDate.getMonth() + 1 === birthdayAge,
discordRoles: {
fork icon0
star icon0
watch icon1

154
155
156
157
158
159
// Relative dates
const fnsDate30Days = add(fnsDate, { days: 30 });

console.log('+30 days', format(fnsDate30Days, 'LLL d, yyyy'));
console.log('relative', formatRelative(fnsDate30Days, fnsDate30Days));
console.log('duration', formatDistance(fnsDate30Days, fnsDate));
fork icon0
star icon0
watch icon2

Other functions in date-fns

Sorted by popularity

function icon

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