new Date() for timezones

Grantham Good

Member
Feb 27, 2020
43
23
8
Hi There

We can use new Date() to return a date eg Tue Nov 17 2020 09:17:05 GMT+0000 (UTC)

but it would be good to be able to call timezone times that relate to the location of the main teams eg
aestTime = new Date().toLocaleString("en-US", {timeZone: "Australia/Brisbane"});

This does not seem to work at the moment
 
Hey Grantham,

I've had a look into this and it looks like the runtime for processes doesn't understand the .toLocalString, i'll raise this internally and hopefully we can get this resolved soon.

In the meantime, I managed to get this script to output the time in a timezone although it returns the correct time the engine still thinks it's UTC or wherever the server is hosted.

Note: I'm running the server locally in Western Australia, so here's the example and the output.

1605844630409.png
Function:

JavaScript:
function getTimeInZone(offset) {
    d = new Date();
    utc = d.getTime() + (d.getTimezoneOffset() * 60000);
    nd = new Date(utc + (3600000*offset));
    return nd.toLocaleString();
}

Code:
JavaScript:
console.log("Time in Brisbane " + getTimeInZone('+10'));
console.log("Time in where server is " + new Date());

You can change the +10 to whatever timezone you want.

Please let me know how this goes.

Thanks.
 
Last edited:
Just to clarify, I believe regardless of where the instance is based it should be in UTC. So providing the timezone delta hours +10 for AEST should get you to where you want to be. I think this will likely not cater for Daylight Savings though.