Convert a Process Date Variable

If I want to get a Date Variable via Inline javascript by execution.getVariable(), the date variable is in a wrong format which I can’t use to create a valid json:

Sample

execution.setVariable(‘myDate’, new Date())

execution.getVariable(‘myDate’) // Output = Tue Nov 30 2021 20:29:15 GMT+0100

But I need a JSON valid date format which I can later deserialize →
for example: “2021-11-30T19:32:42.006Z”

Anyone has a solution, how to get a Date variable with execution.getVariable in a formatted form ?

What have you done to try to format it?

You probably want to format your execution.getVariable(‘myDate’) with a .getISOString(), assuming that you’re working in Javascript not Java.

Yes, I’m using Javascript. And I’ve tried to use toISOString() but the problem is that the type is not a Date, it auto. converts into a String after using execution.getVariable()

And what’s the impact to you if you convert it before you set it?

execution.setVariable(‘myDate’, new Date().getISOString())

I can’t because the variable is already set in a pre-process. It was just a sample above.

What about doing:
strDate = new Date(execution.getVariable(‘myDate’)).toISOString();

Then use strDate where you want your ISO formatted date string.