Skip to main content

Hi,

does anyone knows how I can get the local time in a BPA JavaScript?  I only get UTC time.

 

Thanks!

 

IFS Cloud 24R1

Does the normal Javascript  new Date().toLocaleString() work within BPA?


Hi,

new Date().toLocaleString() works, but also only gives UTC.

 

Snip:


//var expDate = new Date();
var expDate = new Date().toLocaleString();
 

var d = Date.now();
execution.setVariable('DateTime' , new java.sql.Timestamp(d));
execution.setVariable('DateTime2',expDate.toString());
execution.setVariable('DateTime3',expDate.toLocaleString('de-DE', { timeZone: 'CET' }));
//execution.setVariable('DateTime4',expDate.toUTCString());
execution.setVariable('DateTime5',expDate);
//execution.setVariable('DateTime6',expDate.getHours());
//execution.setVariable('DateTime7',expDate.getUTCHours());
 

Does the BPA needs somewhere Basic Data settings? Our Application TimeZone is set correctly.

And the BPA reports for itself the correct time:

Any further ideas, thanks?

 


I may be wrong on this, but I think this is because the JS code you’re recording in the script task is not actually executed by your client (browser) but “internally” by the Camunda engine.


Reason I say this is because if you run this :

 

var offSet = new Date().getTimezoneOffset();

 

You’ll get 0 as a result. (At least from what I tried).

 

This indicates that whatever process runs the workflow script is internal and set to an UTC timezone, meaning it always has zero offset to UTC, which is why .toLocaleString() returns UTC, as it’s local to the place that’s being executed (the Camunda Engine, not your browser).

 

 


Just to add to that, based on the Camunda documentation itself:

 

 

Highly likely that IFS integration with Camunda uses a JVM that is set ot UTC as recommended by Camunda themselves :)


Dear Simon,

thank you very much! This explains why I only get UTC and nothig else. Of course TimezoneOfset is then always 0. 

Ok, I will help myself eihter with an custom field or by calculating CET and CEST in the script. Because of well defined government laws the is a claer algorithm derivable 🙂, I Think I try custom field first or may find a apropriate datetime somewhere in the process in order to take it and write it in my desired attribute.

Again many thanks!

 


Reply