thymeleaf / thymeleaf-extras-java8time

Thymeleaf "extras" dialect for formatting and creating Java 8 Time API objects
Apache License 2.0
106 stars 34 forks source link

How can I use a specific timezone for formatting? #4

Closed cplaetzinger closed 8 years ago

cplaetzinger commented 9 years ago

On server side all my date-time objects are stored using java.time.LocalDateTime and all times are in UTC. The user can choose a timezone in his personal settings. Is there a way to use the users timezone for formatting in thymeleaf templates?

Regards Christian

jmiguelsamper commented 9 years ago

Hello,

the formatting depends on the Temporal class used.

For example, for a LocalDate no hours and minutes are shown but for a LocalDateTime they are, as the Temporal object contains this information.

So, if you use a ZonedDateTime or an OffsetTime, for example, the time zone should be shown.

Take a look at https://github.com/thymeleaf/thymeleaf-extras-java8time/blob/2.1-master/src/test/java/org/thymeleaf/extras/java8time/expression/TemporalsClassesFormattingTest.java to see all possible cases.

And be sure of using the last snapshot where this was fixed.