首页 > 解决方案 > momentjs 中的“无效日期”

问题描述

我有个约会:

let date = "15:00";

我想将其处理为 format: 2019-09-26T15:00:00.000Z,但 momentjs 得到和无效日期错误。

我尝试使用moment(date).format('LTS');

标签: javascriptdatemomentjs

解决方案


您还应该添加值的格式,如下所示:

let date = "15:00";

let m = moment(date, 'HH:mm').toISOString();
console.log(m);

因为你需要这样的东西2019-09-26T15:00:00.000Z,所以最好使用toISOString函数,而不是format.


推荐阅读