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

前端 未结 23 1155
爱一瞬间的悲伤
爱一瞬间的悲伤 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条回答
  •  闹比i
    闹比i (楼主)
    2020-11-22 02:08

    One line solution

    new Date(new Date(1422524805305).getTime() - 330*60*1000)
    

    Instead of 1422524805305, use the timestamp in milliseconds Instead of 330, use your timezone offset in minutes wrt. GMT (eg India +5:30 is 5*60+30 = 330 minutes)

提交回复
热议问题