[RESOLVED] toLocaleString with timeZone does not work?
Hi,
I have two time/date fields and I'm trying to change timezone for the second field to show different timezone's time, but it seems that timezones does not work at all.
Is it a bug or feature?
Here is an example:
let date = new Date(1682931600000);
console.log("Dates:");
console.log(new Date(date).toLocaleString('en-US', {timeZone: 'Etc/UTC'}));
console.log(new Date(date).toLocaleString('en-US', {timeZone: 'Europe/Kyiv'}));
console.log(new Date(date).toLocaleString('en-US', {timeZone: 'Europe/Amsterdam'}));
The results are the same.
Dates:
Mon May 01 2023 09:00:00 GMT+0000 (GMT)
Mon May 01 2023 09:00:00 GMT+0000 (GMT)
Mon May 01 2023 09:00:00 GMT+0000 (GMT)
Expected results:
Dates:
5/1/2023, 9:00:00 AM
5/1/2023, 12:00:00 PM
5/1/2023, 11:00:00 AM
Please sign in to leave a comment.
Hello Viacheslav.
You can use the format function of the date-time for this purpose.
You will need to reference the module in the beginning of your workflow code:
To provide an example, you can then paste the part below to the action section of your workflow rule:
Then trigger the rule and see the result logged in the workflow console toolbar: 1 May 2023 09:00 and 1 May 2023 19:00.
Here is where you can find the list of the supported locale IDs (to be set as the 3rd argument of the format function, as shown on the example above): Available Time Zones.
Hi,
I need to convert date and time to timestamp and use it in date/time field. And this code does not work:
The timestamps are wrong:
What am I doing wrong?
Hi Viacheslav,
I think you forgot to change the variable names in the parse function argument (you have currentTimeKyiv in all three cases here). Also, unfortunately, the Kyiv spelling is not supported at the moment. As the documentation suggests, the zone IDs should be put as they appear in Joda's Available Time Zones. So right now, this should work instead:
However, I've reached out to the team, and it appears there had been an update in tzdata behind the scenes, so Kyiv spelling not working is in fact a bug: JT-75387. Thank you for pointing this out.
Here is the correct way:
And this code works, despite the fact that the time zone is specified as "Europe/Kyiv" and not "Europe/Kiev".