Create a Date with a set timezone without using a string representation

前端 未结 23 1154
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-11-22 01:48

I have a web page with three dropdowns for day, month and year. If I use the JavaScript Date constructor that takes numbers, then I get a Date obje

23条回答
  •  攒了一身酷
    2020-11-22 01:58

    getTimeZoneOffset is minus for UTC + z.

    var d = new Date(xiYear, xiMonth, xiDate);
    if(d.getTimezoneOffset() > 0){
        d.setTime( d.getTime() + d.getTimezoneOffset()*60*1000 );
    }
    

提交回复
热议问题