I am trying to get the difference between a initial date and the date as of right now. I understand when I get the date like this new Date("Feb 17, 2009 12:20:47");
the timezone it gives me is the timezone on my local computer.
I am wondering how I can get the dates in the Sydney Timezone.
var sydneyTime = new Date().toLocaleString("en-US", {timeZone: "Australia/Sydney"});
initDate = new Date("Jan 27, 2009 12:50:37");
rightNow = new Date(sydneyTime);
Question: How do I convert initDate
into Sydney time?
This will work same as your first string. It doesn't have to be only new Date()
can be a defined date as well.
let s = 'Jan 27, 2009 12:50:37'; // Parse as local let d = new Date(s); let sydneyTime = d.toLocaleString(undefined, {timeZone: "Australia/Sydney"}); console.log(`Original date in my location: ${s}\\n\\ Equivalent Sydney time : ${sydneyTime}`);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.