For example, if there is a date string, regardless of whether it has a time zone:2019-10-12T05:24:24.872043Z
, how can I convert it into a date object for the corresponding time zone by using the time zone name Asia/Shanghai
。
Using only JavaScript and not relying on third-party libraries, I know that moment-timezone seems to solve this problem.
The following code can only get a string and cannot be converted to a date object in a given timezone:
var asiaTime = new Date('2019-10-09T08:26:24.289528Z').toLocaleString('en-US', {timeZone: "Asia/Shanghai"});
I expect to get a date object for a given timezone.