When populating a Word document with Date values, Aspose.Words uses timezone of a server/jvm. This means end users get documents in jvm timezone rather than in user’s timezone.
Environment is as follows:
- A server with Aspose.Words in timezone1, java8
- A user from timezone2 initiates document generation.
- Aspose takes a simple word template like shown below, where “event.date” is a java.util.Date object in timezone2
<<foreach [event in events]>> <<[event.date]>> <</foreach>>
- ReportingEngine.buildReport(…) generates a document, where “event.date” is converted to timezone1 (server’s timezone)
As a result, user gets invalid date (in invalid timezone).
According to the link below, there is CurrentThreadSettings public API class
Indeed found it in Aspose.words jar, but couldn’t make it work: compiles ok, but seems to be ignored.
- What would be the correct way of overriding timezone on a per document basis? In my case, server can generate documents from multiple users/timezones in different threads thus need timezone settings per-document.
- Is there API doc for the CurrentThreadSettings class? I could not find docs for it. Could you please provide a link?
- The CurrentThreadSettings class has setTimeZone. But it doesn’t seem to fix timezone issue. Is this correct way to use it?
CurrentThreadSettings.setTimeZone(TimeZone.getTimeZone("Australia/Darwin")); Document doc = new Document(…);