javascript - Is there any conditional formatting in moment.js? -
i working on countdown using moment.js.
nice if have conditional formatting.
here have
var count_down = moment().hour(23).min(30); alert( count_down.format('h[h ]m[min ]s[s]') );
that displays:
0h 43min 20s
i know if there format expression
var format = 'h[h ]m[min ]s[s]'; if (count_down.hour() === 0) format = 'm[min ]s[s]'; alert( count_down.format(format) );
displaying:
43min 20s
i have not seen in doc though.
a moment
object represents time-of-day, not make sense count-down. should use moment's duration
object purpose instead.
moment doesn't yet have direct support formatting durations, this:
var d = moment.duration('23:30'); var s = (d.hours() > 0 ? d.hours() + 'h ' : '') + d.minutes() + 'min ' + d.seconds() + 's';
alternatively, can try moment-duration-format plugin, still have handle conditional evaluation yourself.
Comments
Post a Comment