I can't seem to change to local date with Custom Javascript "toLocaleDateString"
I'm constructing a form where I'm automating the days and adding extra days from the current day. All seems to be working great. The only issue I run into is that my InDesign is in English, and I would like to keep it that way, but the form is in Dutch.
Now The current date and time works fine, i changed it to:
dd MMMM yyyy HH:HHwhich outputs as: 17 augustus 2022 11:11
No problem there. I also changed the Dictinoary to Dutch reform 2005. This does seem to change back to English UK Whenever I open and close the file. Might be the issue?
The .js i use is as follows:
#targetengine 'usernameVariable'
function addVariables(openEvent)
{
var doc = openEvent.parent;
while ( doc.constructor.name != "Document" )
{
if ( doc.constructor.name == "Application" ){ return; }
doc = doc.parent;
}
// from http://stackoverflow.com/questions/563406/add-days-to-datetime
var today = new Date();
var tomorrow = new Date(today);
tomorrow.setDate(today.getDate()+14);
const options = {
year: 'numeric',
month: 'long',
day: 'numeric'
};
createTextVariable(doc, "Days+14", tomorrow.toLocaleDateString('nl-NL', options));
}
function createTextVariable(target, variableName, variableContents)
{
var usernameVariable = target.textVariables.itemByName(variableName);
if (!usernameVariable.isValid)
{
usernameVariable = target.textVariables.add();
usernameVariable.variableType = VariableTypes.CUSTOM_TEXT_TYPE;
usernameVariable.name = variableName;
}
usernameVariable.variableOptions.contents = variableContents;
}
app.addEventListener('afterOpen', addVariables); which outputs as: Wednesday, August 31 2022
I would like it to output as: 31 augustus 2022 Hence:
const options = {
year: 'numeric',
month: 'long',
day: 'numeric'
};
Hopefully some one can help me, thanks in advance.
