Convert date to another timezone in JavaScript

后端 未结 24 3029
没有蜡笔的小新
没有蜡笔的小新 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:39

    Set a variable with year, month, and day separated with '-' symbols, plus a 'T' and the time in HH:mm:ss pattern, followed by +01:00 at the end of the string (in my case the time zone is +1). Then use this string as the argument for the date constructor.

    //desired format: 2001-02-04T08:16:32+01:00
    dateAndTime = year+"-"+month+"-"+day+"T"+hour+":"+minutes+":00+01:00";
    
    var date = new Date(dateAndTime );
    

提交回复
热议问题