我有包含以下日期的数组
{
Mon Feb 17 2020 00:00:00 GMT+0530 (India Standard Time)
,Tue Feb 18 2020 00:00:00 GMT+0530 (India Standard Time)
,Wed Feb 19 2020 00:00:00 GMT+0530 (India Standard Time)
,Thu Feb 20 2020 00:00:00 GMT+0530 (India Standard Time)
}
如何删除时区并将此日期转换为(“日期/月/年”),我需要使用(/)并将它们返回到明智的网格列。这样的例子
- |[17/02/2020] | [18/02/2020] | [19/02/2020]
1 ----- | - | - | -
2 ----- | - | - | -
您可以删除时区部分,将该字符串转换为日期,然后返回适当格式的字符串:
const dates = [
'Mon Feb 17 2020 00:00:00 GMT+0530 (India Standard Time)',
'Tue Feb 18 2020 00:00:00 GMT+0530 (India Standard Time)',
'Wed Feb 19 2020 00:00:00 GMT+0530 (India Standard Time)',
'Thu Feb 20 2020 00:00:00 GMT+0530 (India Standard Time)',
],
result = dates.map(date => new Date(date.replace(/ GMT.*/,'')).toLocaleDateString('en-GB'))
console.log(result)