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

前端 未结 23 1619
爱一瞬间的悲伤
爱一瞬间的悲伤 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
    2020-11-22 02:04

    using .setUTCHours() it would be possible to actually set dates in UTC-time, which would allow you to use UTC-times throughout the system.

    You cannot set it using UTC in the constructor though, unless you specify a date-string.

    Using new Date(Date.UTC(year, month, day, hour, minute, second)) you can create a Date-object from a specific UTC time.

提交回复
热议问题