我正在使用moment.js格式化日期:
const dateFormat = 'DD/MM/YYYY';
setValue('startDate', moment(booking.startDate, dateFormat));
我希望日期为01-06-2020
,而不是2020-06-01T07:33:04.392Z
。任何想法,因为我不知道该怎么做?
这是一个如何将moment.js的实例格式化为DD-MM-YYYY的示例:
const dateString = moment("2020-06-01T12:00:00").format("DD-MM-YYYY");
console.log({ dateString });
这将在控制台中打印以下内容:
{ dateString: '01-06-2020' }
最好阅读有关力矩的format
函数和the standard W3C date and and time formats的更多信息。
这在Momentjs头版https://momentjs.com/中进行了字面解释。首先,将日期时间添加到时刻,然后调用format函数。像这样。
moment('2020-06-01T07:33:04.392Z').format('DD-MM-YYYY')
此返回"01-06-2020"