[英]Angular convert array of dates
I have an array of dates which returns:我有一个返回日期的数组:
[Mon Aug 03 2020 00:00:00 GMT+0100 (British Summer Time), Wed Aug 05 2020 00:00:00 GMT+0100 (British Summer Time)]
I need to convert these into a format as such我需要将它们转换成这样的格式
["2020-02-13T02:39:51.054", "2020-02-13T02:39:51.054"]
Using a function which would be the best way to do this?使用 function 哪个是最好的方法?
I was unable to recreate problem in stack blitz as the dates in stackblitz by default are in my desired format but the project I am working on requires dates in the first format.我无法在堆栈闪电战中重新创建问题,因为默认情况下堆叠闪电战中的日期是我想要的格式,但我正在处理的项目需要第一种格式的日期。 I only need to change format in one array instance.
我只需要在一个数组实例中更改格式。
Use the DatePipe .使用DatePipe 。
let x = ['Mon Aug 03 2020 00:00:00 GMT+0100 (British Summer Time)', 'Wed Aug 05 2020 00:00:00 GMT+0100 (British Summer Time)'];
let a = x.map(a=>this.datePipe.transform(a, 'YYYY-MM-DDTHH:mm:ss.SSS'));
console.log(a);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.