角度6-无法将“无效日期”转换为管道“ DatePipe”的日期

时间:2018-10-29 07:15:10

标签: angular rest typescript angularjs-directive angular6

你好朋友

我正在处理与 日期 转换为期望格式的问题。

实际上, REST API 将日期发送到Milliseconds format中。我想将其转换为特定的日期格式,并想将其注入我的日期标记模型/ ui组件中。在这里,yyyy-MM-dd格式是我的需求格式。

Error类似于Unable to convert "Invalid Date" into a date for pipe "DatePipe".

仅供参考- enter image description here

我的代码也是如此

this.rest.getprofiledata()
           .((resp) =>{
           this.data = resp;
           this.personal = this.data["message"];
           this.d = new Date(this.personal.dob);
           this.personal.dob = this.d;
               var day = this.d.getDate();
               var mon = this.d.getMonth();
               var year = this.d.getFullYear();
               var dy = this.d.getDay();
               dt = new Date(dy,mon,year);
               this.personal.dob = dt
           } );

1 个答案:

答案 0 :(得分:0)

在某些情况下,我使用日期作为

Today is {{myDate | date:'yyyy-MM-dd':'UTC'}}

这对我有用

相关问题