Convert date to another timezone in JavaScript

后端 未结 24 3108
没有蜡笔的小新
没有蜡笔的小新 2020-11-21 04:45

I am looking for a function to convert date in one timezone to another.

It need two parameters,

  • date (in format \"2012/04/10 10:10:30 +0000\")
24条回答
  •  无人及你
    2020-11-21 05:28

    Got it !

    Wanted to force the date shown = server date, no mattter the local settings (UTC).

    My server is GMT-6 --> new Date().getTimezoneOffset() = 360.

    myTZO = 360;
    myNewDate=new Date(myOldDateObj.getTime() + (60000*(myOldDateObj.getTimezoneOffset()-myTZO)));
    alert(myNewDate);
    

提交回复
热议问题