Javascript 以特定格式转换为 GMT

问题描述

我正在使用一个 javascript 日历,它的格式要求非常严格。它要求日期采用以下方式:

我从服务器获取的 UTC 字符串格式 = 2020-04-01T00:00:00Z。 我正在使用的日历库要求将其转换为要使用的日期对象。

let formattedstartDate: Date = new Date(2020-04-01T00:00:00Z);
// Wed Apr 01 2020 01:00:00 GMT+0100 (British Summer Time)

这一切正常,但我需要将其转换为 GMT 时区,然后再将其发送到日历。我在 moment 中看到的所有示例都将其转换为 UTC,但我需要 GMT。

有什么想法吗?

解决方法

你可以使用

new Date('2020-04-01T00:00:00Z').toUTCString()
// Wed,01 Apr 2020 00:00:00 GMT

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...