How to convert date to another timezone in JavaScript? Using toLocaleString() method: The toLocaleString() method is used to return a string that formats the date according to the locale and options specified. It will convert the date on which the method is used from one timezone to another.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | var aestTime = new Date().toLocaleString("en-US", {timeZone: "Australia/Brisbane"}); aestTime = new Date(aestTime); console.log('AEST time: '+aestTime.toLocaleString()) var asiaTime = new Date().toLocaleString("en-US", {timeZone: "Asia/Shanghai"}); asiaTime = new Date(asiaTime); console.log('Asia time: '+asiaTime.toLocaleString()) var usaTime = new Date().toLocaleString("en-US", {timeZone: "America/New_York"}); usaTime = new Date(usaTime); console.log('USA time: '+usaTime.toLocaleString()) var indiaTime = new Date().toLocaleString("en-US", {timeZone: "Asia/Kolkata"}); indiaTime = new Date(indiaTime); console.log('India time: '+indiaTime.toLocaleString()) |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.