Javascript 为了将时间戳转换为格式化日期,如何将HTML端的日期管道实现为TypeScript代码?

Javascript 为了将时间戳转换为格式化日期,如何将HTML端的日期管道实现为TypeScript代码?,javascript,angular,typescript,angular-pipe,Javascript,Angular,Typescript,Angular Pipe,在Angular应用程序中,我将转换一个包含时间戳格式的日期值的变量,如下所示: patientBirthDate: t {seconds: 450568800, nanoseconds: 0} nanoseconds: 0 seconds: 450568800 __proto__: 从组件的HTML转换为日期,方法如下: <span class="image-text">{{patient.birthDate.toMillis() | date:'dd/M

在Angular应用程序中,我将转换一个包含时间戳格式的日期值的变量,如下所示:

patientBirthDate:  
t {seconds: 450568800, nanoseconds: 0}
nanoseconds: 0
seconds: 450568800
__proto__:
从组件的HTML转换为日期,方法如下:

<span class="image-text">{{patient.birthDate.toMillis() | date:'dd/MM/yyyy'}}</span>

但是,如何将其转换为格式化的日期呢?

您可以将
DatePipe
注入组件的构造函数中,并使用
this.DatePipe.transform(日期“”)


类组件{
构造函数(私有datePipe:datePipe){}
formatPatientBirthDate(患者:患者):字符串{
返回这个.datePipe.transform(patient.birthDate.toMillis(),'dd/MM/yyyy');
}
}
console.log("patientBirthDate: ", patient.birthDate.toMillis());