How Mail Merge Engine distinguish between UK and US Date Formats using Java

Hello, I am trying to understand Date formats and Mail Merge.
If I have following code :

    String[] keys = new String[] {"testDate"};
    String[] values = new String[] {"01/02/2021"};
	testDoc.getMailMerge().execute(keys, values);

And if in my template document, my file is defined as :

{ REF testDate  \@ "d' 'MMMM' 'yyyy" \* MERGEFORMAT \* Charformat }

What should be populated in the date : 01/Feb/2021 or 02/Jan/2021

For us, 02/Jan/2021 is populated. Is this happening because my Document language is English (united States), or is there some other reason?

If so, where is the format defined and how can i change it for English language only? (Changing the word document in any way is not an option for us)

Full Program is attached with word document.

regards
Program2.zip (23.1 KB)

@sharma.vikash.mca

In your case, we suggest you please use FieldOptions.FieldUpdateCultureSource property to set the culture to format the field result.

Following code example shows how to specify the source of the culture used for date formatting during a field update or mail merge.

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.moveToDocumentEnd();
// Insert two merge fields with English UK locale.
builder.getFont().setLocaleId(2057);
builder.insertField("MERGEFIELD Date1 \\@ \"dddd, d MMMM yyyy\"");
builder.write(" - ");
builder.insertField("MERGEFIELD Date2 \\@ \"dddd, d MMMM yyyy\"");

// Set the current culture to US English
Locale.setDefault(new Locale("en", "US"));

// This merge will use the current thread's culture to format the date, US English.
doc.getMailMerge().execute(new String[] { "Date1" }, new Object[] { "01/02/2021" });

// Configure the next merge to source its culture value from the field code. The value of that culture will be UK English.
doc.getFieldOptions().setFieldUpdateCultureSource(FieldUpdateCultureSource.FIELD_CODE);
doc.getMailMerge().execute(new String[] { "Date2" }, new Object[] { "01/02/2021" });

System.out.println(doc.toString(SaveFormat.TEXT));

Moreover, you can use Field.LocaleId property to get or set the LCID of the field. Following code example shows how to use Field.LocaleId property.

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.moveToDocumentEnd();
// Insert two merge fields with English UK locale.
//builder.getFont().setLocaleId(2057);
Field field = builder.insertField("MERGEFIELD Date1 \\@ \"dddd, d MMMM yyyy\"");
field.setLocaleId(2057);
builder.write(" - ");
Field field2 = builder.insertField("MERGEFIELD Date2 \\@ \"dddd, d MMMM yyyy\"");
field2.setLocaleId(1033);

doc.getFieldOptions().setFieldUpdateCultureSource(FieldUpdateCultureSource.FIELD_CODE);

doc.getMailMerge().execute(new String[] { "Date1" }, new Object[] { "01/02/2021" });
doc.getMailMerge().execute(new String[] { "Date2" }, new Object[] { "01/02/2021" });

System.out.println(doc.toString(SaveFormat.TEXT));

You can also use FieldOptions.FieldUpdateCultureProvider property to set a provider that returns a culture object specific for each particular field. Please check the code example shared in the following API reference link.
fieldoptions - Aspose.Words for Java - API Reference

@sharma.vikash.mca

Further to my previous post, please use the Field.LocaleId property according to your requirement as shown below. Hope this helps you.

Document doc = new Document(MyDir + "TestDoc.docx");
Field field = (Field)doc.getRange().getFields().get(0);
//field.setLocaleId(1033); //US English locale : 2 January 2021
field.setLocaleId(2057);   //UK English locale :  1 February 2021
String[] keys = new String[] {"testDate"};
String[] values = new String[] {"01/02/2021"};

doc.getFieldOptions().setFieldUpdateCultureSource(FieldUpdateCultureSource.FIELD_CODE);
doc.getMailMerge().execute(keys, values);

System.out.println(doc.toString(SaveFormat.TEXT));