因此,我只需要显示星期几,因此在使用reg ex进行工作之前,我正在moment.js中寻找一种内置的格式化方法。
我得到的是:
moment().add(2, 'days').calendar() = "Thursday at 12:46 PM"
我需要的只是“星期四”
最佳答案
您不想使用calendar
,而是要使用format
:
moment().add(2, 'days').format('dddd') // "Thursday"
API文档说明
calendar
给出the date compared to a reference date,而format
允许您提供format the date how you like。