因此,我只需要显示星期几,因此在使用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

10-04 15:53
查看更多