Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

duration.format("hh:mm:ss") for minutes omits hh: #144

Open
alvipeo opened this issue May 30, 2020 · 4 comments
Open

duration.format("hh:mm:ss") for minutes omits hh: #144

alvipeo opened this issue May 30, 2020 · 4 comments

Comments

@alvipeo
Copy link

alvipeo commented May 30, 2020

duration = moment.duration(8, "minutes);
const s = duration.format("hh:mm:ss");
console.log(s);           // ==> '08:00'

I was expecting it to be "00:08:00"! Is this a bug? If not, how can I get hours part in the string?

v.2.3.2

@alvipeo alvipeo changed the title duration.format("hh:mm:ss") for 8 minutes omits hh: duration.format("hh:mm:ss") for minutes omits hh: May 30, 2020
@floriandotorg
Copy link

+1

@jimvaneijk
Copy link

jimvaneijk commented Jun 19, 2020

@alvipeo

Add {trim: false} to your format like so:

const s = duration.format("hh:mm:ss", {trim: false});

see (#68)

@juicycool92
Copy link

thats what im looking for. but is there any way to {trim: false} for default settings?
all my codes are expect with no trim, so i have to give a setting everytime i formatting :<

@juicycool92
Copy link

그게 내가 찾고있는거야. 하지만 기본 설정에 대해 {trim: false}하는 방법이 있습니까? 내 모든 코드는 트리밍 없이 예상되므로 포맷할 때마다 설정을 지정해야 합니다.<

ohh nvm i figured out.
if someone having trouble like me :
try this

import moment from 'moment';
import 'moment-duration-format';
moment.duration.fn.format.defaults.trim = false;

console.log( moment.duration( 600, 'seconds' ).format( 'HH:mm:ss' ) ) // 00:30:00
console.log( moment.duration( 600, 'seconds' ).format( 'HH:mm:ss', { trim: false } ) ) // 00:30:00

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants