date-fns APIs
- format
- parseISO
- addDays
- formatDistance
- formatDistanceToNow
- isBefore
- differenceInDays
- isToday
- isSameDay
- startOfDay
- subDays
- isValid
- addSeconds
- addMonths
- startOfMonth
- compareAsc
- addHours
- addMinutes
- formatDistanceStrict
- parse
- isYesterday
- isAfter
- getYear
- intervalToDuration
- endOfMonth
- differenceInHours
- formatISO
- differenceInMinutes
- addYears
- setMinutes
- setHours
- endOfDay
- isDate
- sub
- set
- startOfWeek
- differenceInCalendarMonths
- getDay
- addWeeks
- differenceInMonths
- fromUnixTime
- subMinutes
- isWithinInterval
- differenceInSeconds
- subHours
- differenceInCalendarDays
- getMinutes
- differenceInYears
- getHours
- endOfWeek
- setSeconds
- startOfToday
- startOfHour
- max
- differenceInMilliseconds
- endOfYear
- startOfYear
- isTomorrow
- differenceInCalendarYears
- endOfHour
- startOfMinute
- setYear
- setMonth
- subYears
- min
- getSeconds
- compareDesc
- getMonth
- endOfToday
- lastDayOfMonth
- differenceInCalendarWeeks
- subMonths
- lightFormat
- isSameMonth
- eachDayOfInterval
- getDate
- isMatch
- add
- formatDistanceToNowStrict
- formatRelative
date-fns#formatRelative JavaScript Examples
The following examples show how to use
date-fns#formatRelative.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Message.js From react-firechat with MIT License | 6 votes |
formatDate = date => {
let formattedDate = '';
if (date) {
// Convert the date in words relative to the current date
formattedDate = formatRelative(date, new Date());
// Uppercase the first letter
formattedDate =
formattedDate.charAt(0).toUpperCase() + formattedDate.slice(1);
}
return formattedDate;
}