question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How we can format the duration in dayjs.

See original GitHub issue

I have tried o use this but it does not work

import dayjs from 'dayjs';
import duration from 'dayjs/plugin/duration';
dayjs.extend(duration);
const toTimeFormat = (milliseconds: number) => {
  return dayjs.duration(milliseconds).format('HH:mm:ss')
};

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:18
  • Comments:20 (6 by maintainers)

github_iconTop GitHub Comments

19reactions
tejasupmanyucommented, Nov 22, 2021

Hi! can we remove zero values from formatted result? for example - dayjs.duration(1500, 'seconds').format('H[h] m[m] s[s]')

gives 0h 25m 0s

I’d like it to be just 25m

6reactions
EarlOldcommented, Sep 18, 2020

We need it too.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Format
Get the formatted duration according to the string of tokens passed in. ... dayjs.duration({ seconds: 1, minutes: 2, hours: 3, days: 4, months:...
Read more >
Dayjs: Any workaround for format duration in h m
Seems the library converts the 24hrs to 1 day and puts the remaining 1 hour in hours. Actually, I want the output as...
Read more >
How to use the dayjs.duration function in dayjs - Snyk
To help you get started, we've selected a few dayjs examples, based on popular ways it is used in public projects. ; data)...
Read more >
date and time in JavaScript with Day.js - ZetCode
Day.js is a minimalist JavaScript date library for parsing, validating, manipulating, and formatting dates. It is an alternative library to ...
Read more >
The Complete Guide to Day.js - Mirza Leka - Medium
Custom Parse Format extends dayjs() the constructor to support custom formats of input strings. Basically, it allows us to pass the date format...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found