加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

angular – 类型’Moment’不能指定为’Date’类型. ‘Moment’

发布时间:2020-12-17 06:49:04 所属栏目:安全 来源:网络整理
导读:我用angular2应用程序配置了一下,当我试图将本周星期六的日期分配给日期类型变量时, case "weekend": this.fromDate = moment().startOf('week'); 它显示错误说, Type 'Moment' is not assignable to type 'Date'. Property 'toDateString' is missing in ty
我用angular2应用程序配置了一下,当我试图将本周星期六的日期分配给日期类型变量时,

case "weekend":         
        this.fromDate =  moment().startOf('week');

它显示错误说,

Type 'Moment' is not assignable to type 'Date'.   Property 'toDateString' is missing in type 'Moment'

我在我的组件中输入了以下内容,

import * as moment from 'moment/moment';

解决方法

startOf

Mutates the original moment by setting it to the start of a unit of time

所以它返回一个时刻对象.如果需要转换为JavaScript日期,请使用toDate().

case "weekend":         
    this.fromDate =  moment().startOf('week').toDate();

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读