开发者

How to take daylight savings time in to consideration when converting timezones in Javascript?

Currently I have this code:

var databaseTimeZoneMS = -240 * 60000;

var time = ('' + date_str).replace(/-/g,"/").replace(/[TZ]/g," "),
    dt = new Date,
    s开发者_运维百科econds = ((dt - new Date(time) + ((dt.getTimezoneOffset() * 60000) + databaseTimeZoneMS)) / 1000),

However, if daylight savings time is not in effect databaseTimeZoneMS should be -300 * 60000. How can I check if it is daylight savings time? Is this even the right way of solving this problem? It seems rather messy and inelegant.


You should probably (well, definitely) make sure that your server-side code deposits its actual current time zone offset onto each page somehow. Armed with that, you will be able to figure out the difference between the client and the database server.

These sorts of things are always fragile, however, so things might be better if you make sure that all time communications are made in UTC terms.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜