英文字典

别名键 简写键
year years y
quarter quarters Q
month months M
week weeks w
day days d
hour hours h
minute minutes m
second seconds s
millisecond milliseconds ms

格式化时间

moment().format();
moment().format(String);

moment().format('YYYY-MM-DD HH:mm:ss');
// => 2021-05-27 16:15:14

相对现在的时间

别忘了引入相应的语言包

moment().fromNow();
moment([2007, 0, 29]).fromNow();
// => 4 年前

moment().fromNow(Boolean);
moment([2007, 0, 29]).fromNow(true); 
// => 4 年

相对指定的时间(a相当于b)

别忘了引入相应的语言包

var a = moment([2007, 0, 28]);
var b = moment([2007, 0, 29]);

a.from(b);
// "1 天前"

a.from([2007, 0, 29]);         
// "1 天前"

a.from(new Date(2007, 0, 29)); 
// "1 天前"

a.from("2007-01-29");          
// "1 天前"

相对指定的时间(b相当于a)

别忘了引入相应的语言包

var a = moment([2007, 0, 28]);
var b = moment([2007, 0, 29]);
a.to(b);                     
// "1 天内"

a.to([2007, 0, 29]);         
// "1 天内"

a.to(new Date(2007, 0, 29)); 
// "1 天内"

a.to("2007-01-29");          
// "1 天内"

未整理的(搞不懂)

  • calendar