jsmreese / moment-duration-format

Format function plugin for the Moment Duration object.
MIT License
969 stars 120 forks source link

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

Open alvipeo opened 4 years ago

alvipeo commented 4 years ago
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

floriandotorg commented 4 years ago

+1

jimvaneijk commented 4 years ago

@alvipeo

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

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

see (https://github.com/jsmreese/moment-duration-format/issues/68)

juicycool92 commented 2 years ago

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 commented 2 years ago

그게 내가 찾고있는거야. 하지만 기본 설정에 대해 {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