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
OtherRelated APIs
date-fns#differenceInSeconds JavaScript Examples
The following examples show how to use
date-fns#differenceInSeconds.
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: utils.js From matx-react with MIT License | 7 votes |
export function getTimeDifference(date) {
let difference = differenceInSeconds(new Date(), date);
if (difference < 60) return `${Math.floor(difference)} sec`;
else if (difference < 3600) return `${Math.floor(difference / 60)} min`;
else if (difference < 86400) return `${Math.floor(difference / 3660)} h`;
else if (difference < 86400 * 30) return `${Math.floor(difference / 86400)} d`;
else if (difference < 86400 * 30 * 12) return `${Math.floor(difference / 86400 / 30)} mon`;
else return `${(difference / 86400 / 30 / 12).toFixed(1)} y`;
}