1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
| console.log(moment.duration()); console.log( moment.duration(100), moment.duration(2, "seconds"), moment.duration(3, "minutes"), moment.duration(1, "M"), moment.duration({ seconds: 1, minutes: 2, hours: 3, days: 4, weeks: 5, months: 6, years: 7, }), moment.duration("23:59:59") ); var d1 = moment.duration(); var d2 = d1.clone(); d1.add(1, "second"); console.log(d1, d2); moment.locale("zh-cn"); console.log( moment.duration(1, "minutes").humanize(), moment.duration(24, "hours").humanize(), moment.duration(1, "minutes").humanize(true), moment.duration(-1, "minutes").humanize(true) ); console.log( moment.duration(500).milliseconds(), moment.duration(1500).milliseconds(), moment.duration(15000).milliseconds(), moment.duration(500).asMilliseconds(), moment.duration(1500).asMilliseconds(), moment.duration(15000).asMilliseconds() ); console.log( moment.duration(500).seconds(), moment.duration(1500).seconds(), moment.duration(15000).seconds(), moment.duration(500).asSeconds(), moment.duration(1500).asSeconds(), moment.duration(15000).asSeconds() ); var a = moment.duration(1, "d"); var b = moment.duration(2, "d"); console.log( a.add(b).days(), moment.duration().add(1, "d").days() ); var a = moment.duration(3, "d"); var b = moment.duration(2, "d"); console.log( a.subtract(b).days(), moment.duration(5, "d").subtract(1, "d").days() ); var a = moment([2018, 10, 21, 10, 05]); var b = moment([2018, 10, 21, 10, 06]); console.log(moment.duration(b.diff(a))); console.log( moment.duration(1000).as("milliseconds"), moment.duration(1000).as("seconds") ); var d = moment.duration({ seconds: 1, minutes: 2, hours: 3, days: 4, months: 5, years: 6, }); console.log(d); console.log( d.get("seconds"), d.get("minutes"), d.get("hours"), d.get("days"), d.get("months"), d.get("years") );
|