我有以下日期 Thu Apr 02 2020 11:57:21 GMT+0200 (Středoevropský letní čas)
。我需要将此日期与 API 中存储的日期进行比较。问题是API中的日期格式是2020-06-27T12:34:00.000Z
。
有什么方法可以将第一个日期的格式转换为与第二个日期相同吗?或者我可以以某种方式比较它们,格式并不重要?
提前谢谢您。
最佳答案
使用Date.prototype.toISOString()
The toISOString() method returns a string in simplified extended ISO format (ISO 8601),
which is always 24 or 27 characters long (YYYY-MM-DDTHH:mm:ss.sssZ
or±YYYYYY-MM-DDTHH:mm:ss.sssZ
, respectively).
The timezone is always zero UTC offset, as denoted by the suffix "Z".
const time = 'Thu Apr 02 2020 11:57:21 GMT+0200 (Středoevropský letní čas)'
const result = new Date(time).toISOString();
console.log(result);
关于javascript - 转换日期格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60989034/