angular 中的日期转换

Date conversion in angular

我正在开发 angular 应用程序。我有一个格式为 2020-08-11T19:00:00 的日期,但我想要 1-Jun-2021 格式的日期。我尝试使用日期管道来做到这一点,如下所示:

{{2020-08-11T19:00:00  | date:'d-MMM-y'}}

但是它给出了解析错误

"Parser Error: Unexpected token 'T19'"

我如何使用日期管道来做到这一点?

您在日期输入前后放错了双引号 ",这就是为什么出现此错误的原因。

 {{ "2020-08-11T19:00:00" | date:'d-MMM-y'}} 

尝试在日期前后加上引号。

{{ '2020-08-11T19:00:00'  | date:'d-MMM-y'}}

DatePipe is executed only when it detects a pure change to the input value. A pure change is either a change to a primitive input value (such as String, Number, Boolean, or Symbol), or a changed object reference (such as Date, Array, Function, or Object).

参考:Angular DatePipe