Change Timezone for Date variable

后端 未结 1 1910
既然无缘
既然无缘 2021-01-14 10:50

I have a string, and I have converted it into a Date variable. But the timezone is turning out to be wrong.

The string I\'m trying to use is :

var v          


        
相关标签:
1条回答
  • 2021-01-14 11:33

    2013/09/05 17:53 -05:00 is the same time as Thu Sep 05 2013 18:53:00 GMT-0400; both are Thu, 05 Sep 2013 22:53:00 GMT

    In JavaScript, you have two choices (natively) about how to display a time; in the local machine's timezone (Date.prototype.toString) or in UTC (Date.prototype.toUTCString). If you want to display a time as a string with a different time zone, you will have to write a function to do it manually, calculating it from UTC.

    The two main articles on MDN which will help you with how to use a Date are Date and Date.prototype.

    0 讨论(0)
提交回复
热议问题