如何在Javascript中将此日期格式 2021-03-30T06:14:00.000Z 转换为 2021-03-30T06:14:00+00:00 此日期格式

时间:2021-03-31 07:08:52

标签: javascript jquery date simpledateformat date-format

我想在 Javascipt 中将 2021-03-30T06:14:00.000Z 日期格式转换为 2021-03-30T06:14:00+00:00 日期格式。

2 个答案:

答案 0 :(得分:1)

使用字符串替换方法...例如

let time = '2021-03-30T06:14:00.000Z';
let newTime = '2021-03-30T06:14:00.000Z'.replace('.000Z','+00:00')

答案 1 :(得分:1)

您可以在替换方法中使用正则表达式,例如:

let time = '2021-03-30T06:14:00.000Z'; 
let newTime = '2021-03-30T06:14:00.000Z'.replace(/(\.[0-9]*Z)$/g,'+00:00')

以及所有以 .然后是数字,在它的 Z 将被替换为 +00:00