# thymeleaf-extras-java8time **Repository Path**: rsl-pro/thymeleaf-extras-java8time ## Basic Information - **Project Name**: thymeleaf-extras-java8time - **Description**: No description available - **Primary Language**: Unknown - **License**: Apache-2.0 - **Default Branch**: 2.1-dev - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2018-02-09 - **Last Updated**: 2020-12-19 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README Thymeleaf - Module for Java 8 Time API compatibility ==================================================== ------------------------------------------------------------------------------ Status ------ This is a *thymeleaf extras* module, not a part of the Thymeleaf core (and as such following its own versioning schema), but fully supported by the Thymeleaf team. Current versions: * **Version 2.1.0.RELEASE** - for Thymeleaf 2.1 (requires 2.1.3+) License ------- This software is licensed under the [Apache License 2.0] (http://www.apache.org/licenses/LICENSE-2.0.html). Requirements ------------ * Java **8** * Thymeleaf **2.1.3+** Maven info ---------- * groupId: `org.thymeleaf.extras` * artifactId: `thymeleaf-extras-java8time` Distribution packages --------------------- Distribution packages (binaries + sources + javadoc) can be downloaded from [SourceForge](http://sourceforge.net/projects/thymeleaf/files/thymeleaf-extras-java8time/). Installation ------------ Just add the `org.thymeleaf.extras.java8time.dialect.Java8TimeDialect` class to the list of dialects in your TemplateEngine implementation, and you will have the `#temporals` object available to be used in your templates. ```java TemplateEngine templateEngine = new TemplateEngine(); templateEngine.addDialect(new Java8TimeDialect()); ... ``` Features -------- This module adds a `#temporals` object similar to the `#dates` or `#calendars` ones in the Standard Dialect, allowing the formatting and creation of temporal objects from Thymeleaf templates. ![Java 8 Time API](/src/main/resources/temporal.png "Java 8 Time API") Usage ----- ```java /* * ============================================================================= * See javadoc API for class org.thymeleaf.extras.java8time.expression.Temporals * ============================================================================= */ /* * Format date with the standard locale format * Also works with arrays, lists or sets */ ${#temporals.format(temporal)} ${#temporals.arrayFormat(temporalsArray)} ${#temporals.listFormat(temporalsList)} ${#temporals.setFormat(temporalsSet)} /* * Format date with the standard format for the provided locale * Also works with arrays, lists or sets */ ${#temporals.format(temporal, locale)} ${#temporals.arrayFormat(temporalsArray, locale)} ${#temporals.listFormat(temporalsList, locale)} ${#temporals.setFormat(temporalsSet, locale)} /* * Format date with the specified pattern * Also works with arrays, lists or sets */ ${#temporals.format(temporal, 'dd/MMM/yyyy HH:mm')} ${#temporals.arrayFormat(temporalsArray, 'dd/MMM/yyyy HH:mm')} ${#temporals.listFormat(temporalsList, 'dd/MMM/yyyy HH:mm')} ${#temporals.setFormat(temporalsSet, 'dd/MMM/yyyy HH:mm')} /* * Format date with the specified pattern and locale * Also works with arrays, lists or sets */ ${#temporals.format(temporal, 'dd/MMM/yyyy HH:mm', locale)} ${#temporals.arrayFormat(temporalsArray, 'dd/MMM/yyyy HH:mm', locale)} ${#temporals.listFormat(temporalsList, 'dd/MMM/yyyy HH:mm', locale)} ${#temporals.setFormat(temporalsSet, 'dd/MMM/yyyy HH:mm', locale)} /* * Format date with ISO-8601 format * Also works with arrays, lists or sets */ ${#temporals.formatISO(temporal)} ${#temporals.arrayFormatISO(temporalsArray)} ${#temporals.listFormatISO(temporalsList)} ${#temporals.setFormatISO(temporalsSet)} /* * Obtain date properties * Also works with arrays, lists or sets */ ${#temporals.day(temporal)} // also arrayDay(...), listDay(...), etc. ${#temporals.month(temporal)} // also arrayMonth(...), listMonth(...), etc. ${#temporals.monthName(temporal)} // also arrayMonthName(...), listMonthName(...), etc. ${#temporals.monthNameShort(temporal)} // also arrayMonthNameShort(...), listMonthNameShort(...), etc. ${#temporals.year(temporal)} // also arrayYear(...), listYear(...), etc. ${#temporals.dayOfWeek(temporal)} // also arrayDayOfWeek(...), listDayOfWeek(...), etc. ${#temporals.dayOfWeekName(temporal)} // also arrayDayOfWeekName(...), listDayOfWeekName(...), etc. ${#temporals.dayOfWeekNameShort(temporal)} // also arrayDayOfWeekNameShort(...), listDayOfWeekNameShort(...), etc. ${#temporals.hour(temporal)} // also arrayHour(...), listHour(...), etc. ${#temporals.minute(temporal)} // also arrayMinute(...), listMinute(...), etc. ${#temporals.second(temporal)} // also arraySecond(...), listSecond(...), etc. ${#temporals.nanosecond(temporal)} // also arrayNanosecond(...), listNanosecond(...), etc. /* * Create temporal (java.time.Temporal) objects from its components */ ${#temporals.create(year,month,day)} // return a instance of java.time.LocalDate ${#temporals.create(year,month,day,hour,minute)} // return a instance of java.time.LocalDateTime ${#temporals.create(year,month,day,hour,minute,second)} // return a instance of java.time.LocalDateTime ${#temporals.create(year,month,day,hour,minute,second,nanosecond)} // return a instance of java.time.LocalDateTime /* * Create a temporal (java.time.Temporal) object for the current date and time */ ${#temporals.createNow()} // return a instance of java.time.LocalDateTime ${#temporals.createNowForTimeZone(zoneId)} // return a instance of java.time.ZonedDateTime ${#temporals.createToday()} // return a instance of java.time.LocalDate ${#temporals.createTodayForTimeZone(zoneId)} // return a instance of java.time.LocalDate /* * Create a temporal (java.time.Temporal) object for the provided date */ ${#temporals.createDate(isoDate)} // return a instance of java.time.LocalDate ${#temporals.createDateTime(isoDate)} // return a instance of java.time.LocalDateTime ${#temporals.createDate(isoDate, pattern)} // return a instance of java.time.LocalDate ${#temporals.createDateTime(isoDate, pattern)} // return a instance of java.time.LocalDateTime ```