Free Support Forum - aspose.com

Date Formatting of Message

I am having trouble getting the MhtSaveOptions format template for DateTime working as I expect it to for some Java date formatting options. Does it not support all the simple date formatting of standard Java?

String emailPath = "some_email";
FileInputStream fstream = new FileInputStream(emailPath);
MailMessage eml = MailMessage.load(fstream);
MhtSaveOptions saveOptions = SaveOptions.getDefaultMhtml();
saveOptions.getFormatTemplates().add(MhtTemplateName.DATE_TIME, "MMMM d, YYYY hh:mm a (zzzZZZ)");
ByteArrayOutputStream emlStream = new ByteArrayOutputStream();
eml.save(emlStream, saveOptions);

I was expecting the date to look like (this is the format if you do use a SimpleDateFormat object):
October 7, 2019 11:36 AM (CDT-0500)
but it was:
October 7, YYYY 11:36 AM (-06:00ZZZ)

I couldn’t find any documentation about this feature.

@mstandfuss,

Thanks for contacting us. Can you please share source file so that we may further investigate to help you out.

It would be any email file but I have attached an example problems.zip (161.0 KB)

@mstandfuss,

Thanks for sharing requested files. I like to inform that MhtTemplateName.DATE_TIME format string does not support Timezone short name abbreviation. Following is format without short name abbreviation.

“MMMMM d, yyyy HH:mm a (zzz)”

Is that documented anywhere? I was assuming that it supported normal Java date formattings [1], but I am guessing there might be other differences in the two.

[1] https://docs.oracle.com/javase/8/docs/api/java/text/SimpleDateFormat.html

@mstandfuss,

Can you please explain your query in more detail.

Where in your documentation does it have all the accepted formats? I was making the assumption that it used the same formats as the Java standard date formatting strings (link above), but that’s not true since it doesnt support timezones like shown above.

@mstandfuss,

I like to inform that we are updating our documentation according to new features and this will be included too.

Can you share a link to this, or the text of what will eventually be included? Currently its a trial and error process to know what formats are supported.

For example I am trying another format of:

EEE, d MMM yyyy HH:mm:ss z
“Tue, 12 Feb 2019 23:07:16 UTC”

But it appears that the ‘EEE’ date and ‘z’ timezone formats are also not supported, since its shown as:

“, 12 Feb 2019 23:07:16 +0”

I dont understand why wouldnt the standard Java date formatting isnt used or supported.

@mstandfuss

I like to inform that new features are added in new version on monthly basis. You may check latest version release notes from this link.

@mstandfuss,

We need to use short day of week format, “EEE” instead of “EEEE”
“EEE, dd-MM-yyyy HH:mm:ss”

We use our own implementation of datetime parsing similar as .Net(for Aspose.Email .Net implementation compatibility). For reference, please visit this link.

Thank you for linking that. I am not sure I understand the use of a C# standard in a Java Library, especially with no formal documentation to lead you to that knowledge. Can I ask that something be logged to get your Java framework up to Java date formattings? We use those formattings for other logic around emails and now we will not be able to match our PDF printouts to those other dates.

@mstandfuss,

We have created an issue with ID EMAILJAVA-34600 in our issue tracking system to further investigate the issue w.r.t Aspose.Email for Java. This thread has been linked with the issue so that you may be notified once the issue will be fixed.

It looks like this was included in the latest release of PDF 19.10. Can I ask what was done? I dont see any new documentation of the enhancement other than this in the release notes

EMAILJAVA-34600 Date Formatting of Message Enhancement

Which is not very useful.

@mstandfuss,

I like to inform that we can only display timezone name only for local DateTime. Can you please try to use following sample code on your end and share feedback with us if there is still an issue.

MailMessage eml = MailMessage.load(fstream);
MhtSaveOptions saveOptions = SaveOptions.getDefaultMhtml();
//Defines whether need keep original date in mail message when saving or not.
//Default value is true.
//Only in case PreserveOriginalDate(false) the date is local and "ZZZZ" will be interpreted as "CDT-0500" otherwise only offset "-05:00"
saveOptions.setPreserveOriginalDate(false);
// DATE_TIME template output - "October 7, 2019 11:36 AM (CDT-0500)"
saveOptions.getFormatTemplates().add(MhtTemplateName.DATE_TIME, "MMMM d, YYYY hh:mm a (ZZZZ)");