Why is there GMT+0805 (China Standard time)?
1. Question:
Google browser
console enter: new Date (1899,11,31,0,0,0)
print: Sun Dec 31 1899 00:00:00 GMT+0805 (China Standard time)
2. Question: Why does + 0805 appear, and how to avoid or replace it?
PS: will use getTime (), getTimezoneOffset () later
Thank you.
because before 1901, Shanghai time was + 8:05:43, until after 1901, it was switched to the real East eighth District, that is, + 8moral chrome. Referring to the following website, you can see the time migration over the years
.
https://www.timeanddate.com/t.
however, on my chrome version, I returned Sun Dec 31 1899 00:00:00 GMT+0800, estimated to be related to the chrome version.
Thank you for @ i38me's popular science.
has just tried moment.js to replace it, which is feasible for the time being. If you encounter the same problem in the new version of Google browser, please refer to the following:
thought:
1. To obtain the time zone of 1899 (for example: Shanghai, China):
moment ([1899 Magi 11 Magi 31je 0je 0]). UtcOffset () has been abandoned in place of getTimezoneOffset () PS:zone, there is a positive or negative problem that has not been studied, note that
= > 480
, that is, East eighth District
2.It is worth noting that < 1899 > = > 480 < Shanghai > is the East eighth District
2. Convert 480 words = > + 0800 (write down the general function yourself)
3.moment ("1899-12-31 0:0:0 + 0800", "YYYY-MM-DD HH:mm Z"). ValueOf () can replace getTime ()
temporary solution
2018-12-29 added:
alternative method
function getTimeFunc(time){
var dateOffset = -moment(moment(time).toArray()).utcOffset();
var timeZ = dateOffset/60 < 0 ? "+" + -dateOffset/60 : dateOffset/60;
return moment(moment(time).format("YYYY-MM-DD HH:mm:ss ") + timeZ, "YYYY-MM-DD HH:mm Z").valueOf();
}
function getTimezoneOffsetFunc(time){
return -moment(moment(time).toArray()).utcOffset();
}