-
Hi, on my blog, I'm displaying reading time in minutes for each of my blog posts. Is there a way to show this information (= the minutes) as a Basically, this stackoverflow post summarizes my situation perfectly. |
Beta Was this translation helpful? Give feedback.
Answered by
maximtop
Jun 29, 2023
Replies: 1 comment 1 reply
-
In date-fns, you can handle this as follows: const duration = { minutes: 13, seconds: 7 };
// Refer to https://date-fns.org/v2.30.0/docs/formatISODuration for documentation
const isoDurationStr = formatISODuration(duration);
console.log(isoDurationStr); // Output: P0Y0M0DT0H13M7S - a valid value for the datetime attribute duration
// Refer to https://date-fns.org/v2.30.0/docs/formatDuration for documentation
const formattedDuration = formatDuration(duration);
console.log(formattedDuration); // Output: 13 minutes 7 seconds - you can use whatever format suits you Here's a CodeSandbox link for this example: https://codesandbox.io/s/date-fns-duration-format-pg2z5k?file=/src/App.js:119-167 |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
niqwithq
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In date-fns, you can handle this as follows:
Here's a CodeSandbox link for this example: https://codesandbox.io/s/date-fns-duration-format-pg2z5k?file=/sr…