我尝试了各种 JavaScript 方法来处理 UTC,包括我在 stackoverflow 上看到的方法,但没有一个适用于这个特定的示例:
var newDate = new Date("Wed Apr 15 2020 00:00:00 GMT+0100 (British Summer Time)");
console.log(newDate);
console.log(new Date(newDate.toGMTString()));
两者的输出是:
Wed Apr 15 2020 00:00:00 GMT+0100 (British Summer Time)
Wed Apr 15 2020 00:00:00 GMT+0100 (British Summer Time)
最佳答案
您正在创建一个新的日期来记录格式化的日期,只需删除新的实例创建即可查看 GMT 时间。
var newDate = new Date("Wed Apr 15 2020 00:00:00 GMT+0100 (British Summer Time)");
console.log(newDate.toGMTString());
无论如何,toGMTString()
方法已被弃用,您应该使用 toUTCString()
代替。
关于javascript - 将英国夏令时间日期更改为 GMT 日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61219239/