How can I parse dates?

I’m evaluating this product and I’m having problems with date formats.

Actually, what I need to do is receive a .docx file and export to .pdf. This process goes fine but for document headers I have a timestamp and using Aspose.words for java I get this format: Version 9/13/2018 3:08:00 PM

However, in my previous implementation (without Aspose.words) I had this: Version 13.09.2018 09:22:00.

I have tried 2 different ways to try to get the desired format, the first was change system’s locale, produce pdf file, restore original locale. The second was to get all Run nodes in the document and change the locale. Both did change nothing.

My sample codes are:

Document doc = new Document(document.getInputStream());
NodeCollection<Run> collection = doc.getChildNodes(NodeType.RUN, true);
for (Run run : collection) {
    run.getFont().setLocaleId(1031); // From MS - German Germany de-de 1031 
}

doc.save(response.getOutputStream(), SaveFormat.PDF);

And:

Locale current = Locale.getDefault();
Locale.setDefault(new Locale("de", "DE"));
Document doc = new Document(document.getInputStream());
doc.save(response.getOutputStream(), SaveFormat.PDF);
Locale.setDefault(current);

Is there something I’m missing?

@IAvilaE,

Please ZIP and upload your simplified input Word document and Aspose.Words generated PDF file showing the undesired behavior here for testing. We will investigate the issue on our end and provide you more information.

Attached there’s a file with docx and pdf files, as well an image with desired output.

Thanks so far.

@IAvilaE,

You can try following methods to workaround this problem:

Code 1:

Locale.setDefault(new Locale("de", "DE"));
Document doc = new Document("D:\\aspose_sample\\aspose_sample.docx");
doc.getFieldOptions().setFieldUpdateCultureSource(FieldUpdateCultureSource.CURRENT_THREAD);
doc.save("D:\\aspose_sample\\awjava-18.9.pdf");

Code 2:

Document doc = new Document("D:\\aspose_sample\\aspose_sample.docx");

PdfSaveOptions opts = new PdfSaveOptions();
opts.setUpdateFields(false);

doc.save("D:\\aspose_sample\\18.9-UpdateFields-false.pdf", opts);

Hope, this helps.

@awais.hafeez

Code 1 did exactly what I needed. Thanks so far for your help :slight_smile: