解析日期没有时区javascript [英] Parse date without timezone javascript
问题描述
新日期(Date.parse(2005-07-08T00:00:00 + 0000)) ;
返回Fri Jul 08 2005 02:00:00 GMT + 0200 中欧夏令时间
新日期(Date.parse(2005-07-08 00:00:00 GMT + 0000 ));
返回相同结果
新日期(Date.parse(2005-07-08 00:00:00 GMT-0000));
返回相同结果
我想解析时间:
-
没有时区。
-
没有调用构造函数Date.UTC或新的日期(年,月,日)。
-
只需简单地将字符串传递给Date构造函数(无原型方法) p>
-
我必须产品
日期
对象,而不是String
。
日期解析正确,只是toString转换它到您当地的时区:
>新日期(Date.parse(2005-07-08T11:22:33 + 0000))
Fri Jul 08 2005 13:22:33 GMT + 0200(CEST)
> new Date(Date.parse(2005-07-08T11:22:33 + 0000))toUTCString()
Fri,08 Jul 2005 11:22:33 GMT
Javascript日期对象是时间戳 - 它们只包含从时代开始的毫秒数。 Date对象中没有时区信息。这个时间戳表示哪个日历日期(天,分钟,秒)是解释的问题(至... String
方法之一)。
上面的例子显示正在解析日期 - 也就是说,它实际上包含对应于2005-07-08T11:22:33的毫秒数在GMT。
I want to parse date without timezone in JavaScript. I have tried:
new Date(Date.parse("2005-07-08T00:00:00+0000"));
Returns Fri Jul 08 2005 02:00:00 GMT+0200 (Central European Daylight Time)
new Date(Date.parse("2005-07-08 00:00:00 GMT+0000"));
Returns same result
new Date(Date.parse("2005-07-08 00:00:00 GMT-0000"));
Returns same result
I want to parse time:
Without time zone.
Without calling constructor Date.UTC or new Date(year, month, day).
Just simple passing string into Date constructor (without prototype approaches).
I have to product
Date
object, notString
.
The date is parsed correctly, it's just toString that converts it to your local timezone:
> new Date(Date.parse("2005-07-08T11:22:33+0000"))
Fri Jul 08 2005 13:22:33 GMT+0200 (CEST)
> new Date(Date.parse("2005-07-08T11:22:33+0000")).toUTCString()
"Fri, 08 Jul 2005 11:22:33 GMT"
Javascript Date object are timestamps - they merely contain a number of milliseconds since the epoch. There is no timezone info in a Date object. Which calendar date (day, minutes, seconds) this timestamp represents is a matter of the interpretation (one of to...String
methods).
The above example shows that the date is being parsed correctly - that is, it actually contains an amount of milliseconds corresponding to "2005-07-08T11:22:33" in GMT.
这篇关于解析日期没有时区javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!