【问题标题】:Type 'DateTimeTimeZone' is not assignable to type 'Date' in Angular 11类型“DateTimeTimeZone”不可分配给 Angular 11 中的“日期”类型
【发布时间】:2021-03-04 22:09:33
【问题描述】:

更新我的整个 Angular 项目后我遇到了一个问题,突然我得到“没有重载与此调用匹配。”并且读取错误“Type 'DateTimeTimeZone' is not assignable to type '日期'。"

这似乎发生在我的日期格式化函数上:

  formattingDate(dateTime: DateTimeTimeZone): String {
    try {
      return (this.datepipe.transform(dateTime, 'dd MMMM yyyy'));
    }
    catch (error) {
      this.alertsService.add('DateTimeTimeZone conversion error', JSON.stringify(error));
    }
  }

虽然 DateTimeTimeZone 包含以下内容:

// https://docs.microsoft.com/graph/api/resources/datetimetimezone?view=graph-rest-1.0
export class DateTimeTimeZone {
  dateTime: string;
  timeZone: string;
}

有没有快速简便的解决方案? 我不知道从哪里开始。

【问题讨论】:

标签: angular typescript datetime microsoft-graph-api overloading


【解决方案1】:

我可以通过使用 moment 和更好的格式类型来解决这个问题:

现在:

try {
  return moment(dateTime.dateTime).format('MM/dd/yyyy');
}

之前:

try {
  return (this.datepipe.transform(dateTime, "dd-MMMM-yyyy"));
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-04-29
    • 2021-07-02
    • 2023-01-11
    • 1970-01-01
    • 2021-05-21
    • 2020-05-20
    • 1970-01-01
    • 2021-06-08
    相关资源
    最近更新 更多