How to use the formatDuration function from date-fns
Find comprehensive JavaScript date-fns.formatDuration code examples handpicked from public code repositorys.
GitHub: gbits-io/gbits-api
209 210 211 212 213 214 215 216 217
if (quota <= 0) { const duration = intervalToDuration({ start: new Date().getTime(), end: tomorrow, }); const formattedDuration = formatDuration(duration, { delimiter: ', ', format: ['hours', 'minutes'], });
0
1
2
GitHub: edfletcher/drc
14 15 16 17 18 19 20 21 22 23
if (allowSeconds) { defOpts.push('seconds'); } const options = { format: defOpts }; const fmt = () => dfns.formatDuration(dfns.intervalToDuration({ start, end }), options); let dur = fmt(); if (!dur) { options.format.push('seconds');
1
13
3
22 23 24 25 26 27 28 29 30
} return stdout; } function durationToString(durationInSeconds) { return formatDuration( intervalToDuration({start: 0, end: durationInSeconds * 1000}) ); }
0
1
2
GitHub: vdloc/netwalker-backend
0 1 2 3 4 5 6 7 8 9 10 11
const { formatDuration, intervalToDuration, format } = require("date-fns"); const vi = require("date-fns/locale/vi"); function getReadableMilis(start, end) { const duration = intervalToDuration({ start, end }); return formatDuration(duration, { locale: vi }); } function getCurrentTime() { return format(new Date(), "dd-MM-yyyy", { locale: vi });
0
0
0
7 8 9 10 11 12 13 14
} else { const duration = fns.intervalToDuration({ start: new Date(0), end: new Date(durationInMillis) }); return fns.formatDuration(duration).replace(/ hours?/, 'h').replace(/ minutes?/, 'm').replace(/ seconds?/, 's'); } };
0
0
8
GitHub: jsonMartin/humidimon
149 150 151 152 153 154 155 156 157 158
lastEntry['interval']['minutes'] * 60 + lastEntry['interval']['hours'] * 60 * 60 + lastEntry['interval']['days'] * 60 * 60 * 24; formatDuration(lastEntry['interval'], { format: ['seconds'] }); lastEntry['duration'] = formatDuration(lastEntry['interval']); } powerSwitchLog.push({ on: getPowerRelayState(),
0
0
2
+ 3 other calls in file
date-fns.format is the most popular function in date-fns (3838 examples)