Angular Ionic 2-将Json日期/日期()转换为字符串

Angular Ionic 2-将Json日期/日期()转换为字符串,angular,ionic2,Angular,Ionic2,如何从REST转换JSON日期 /日期(1480525200000+0700)/ 要以字符串格式dd/MM/yyyy可以创建自定义管道: import { Pipe, PipeTransform } from '@angular/core'; @Pipe({ name: 'myDate' }) export class MyDatePipe implements PipeTransform { transform(value: string): any { return ne

如何从REST转换JSON日期

/日期(1480525200000+0700)/


要以字符串格式dd/MM/yyyy

可以创建自定义管道:

import { Pipe, PipeTransform } from '@angular/core';

@Pipe({
  name: 'myDate'
})

export class MyDatePipe implements PipeTransform {
  transform(value: string): any {
    return new Date(parseInt(value.substr(6)));
  }
}
然后在这样的模板中使用:

<div> date: {{jsonDate | myDate | date:"dd/MM/yyyy"}}</div>
date:{{jsonDate | myDate | date:“dd/MM/yyyy”}
其中
jsonDate
是您的
/日期(1480525200000+0700)/


您可以看到@silentsod提到的上述链接。

可能重复的注意事项,我将您的问题标题
Convert Json date/date()/粘贴到搜索引擎中,重复出现在前5个结果中。谢谢。但我不知道如何在ionic2中使用