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

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

    Use Moment.js (https://momentjs.com/)

    moment().isDST(); will give you if Day light savings is observed.

    Also it has helper function to calculate relative time for you. You don't need to do manual calculations e.g moment("20200105", "YYYYMMDD").fromNow();

提交回复
热议问题