How do you convert a JavaScript date to UTC?

后端 未结 29 2093
无人共我
无人共我 2020-11-22 00:50

Suppose a user of your website enters a date range.

2009-1-1 to 2009-1-3

You need to send this date to a server for some processing, but th

29条回答
  •  北荒
    北荒 (楼主)
    2020-11-22 01:19

    If you need Date Object

    Passing only date string Date assumes time to be 00:00 shifted by time zone:

    new Date('2019-03-11')
    Sun Mar 10 2019 18:00:00 GMT-0600 (Central Standard Time)
    

    If you add current hours and minutes you get proper date:

    new Date('2019-03-11 ' + new Date().getHours() + ':' + new Date().getMinutes())
    Mon Mar 11 2019 04:36:00 GMT-0600 (Central Standard Time)
    

提交回复
热议问题