我想转换2018-04-03T06:08:08-05:00
至
MM.dd.yyyy HH:mm
我如何在Angular 4.x +中执行此操作?
与使用日期使用getHours(),getMinutes()等的vanilla javascript相同。以下是对可能有用的类似问题的引用。
尝试使用:
在html中:
<p>Formatted Date: <b>{{ newdate | date:'MM.dd.yyyy HH:mm' }}</b> </p>
在组件中:
newdate = new Date('2018-04-03T06:08:08-05:00');
输出:
Formatted Date: 04.03.2018 22:29
你需要检查一下:https://angular.io/api/common/DatePipe
正如它在链接中所说,您可以在组件中声明日期,例如:
export class DatePipeComponent {
today = Date.now();
}
然后使用管道将其转换为所需的格式:
{{today | date:'yyyy-MM-dd HH:mm a z':'+0900'}}