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

前端 未结 14 756
栀梦
栀梦 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:22

    The moment.js library provides an .isDst() method on its time objects.

    moment#isDST checks if the current moment is in daylight saving time.

    moment([2011, 2, 12]).isDST(); // false, March 12 2011 is not DST
    moment([2011, 2, 14]).isDST(); // true, March 14 2011 is DST
    

提交回复
热议问题