How to check if DST (Daylight Saving Time) is in effect, and if so, the offset?

前端 未结 14 732
栀梦
栀梦 2020-11-22 09:46

This is a bit of my JS code for which this is needed:

var secDiff = Math.abs(Math.round((utc_date-this.premiere_date)/1000));
this.years = this.calculateUnit         


        
14条回答
  •  有刺的猬
    2020-11-22 10:19

    Is there an issue using the Date.toString().indexOf('Daylight Time') > -1

    "" + new Date()

    Sat Jan 01 100050 00:00:00 GMT-0500 (Eastern Standard Time)

    "" + new Date(...)

    Sun May 01 100033 00:00:00 GMT-0400 (Eastern Daylight Time)

    This seems compatible with all browsers.

提交回复
热议问题