https://github.com/thymeleaf/thymeleaf-extras-java8time
Thymeleaf "extras" dialect for formatting and creating Java 8 Time API objects
https://github.com/thymeleaf/thymeleaf-extras-java8time
Last synced: 11 months ago
JSON representation
Thymeleaf "extras" dialect for formatting and creating Java 8 Time API objects
- Host: GitHub
- URL: https://github.com/thymeleaf/thymeleaf-extras-java8time
- Owner: thymeleaf
- License: apache-2.0
- Created: 2014-11-14T13:00:44.000Z (over 11 years ago)
- Default Branch: 3.0-master
- Last Pushed: 2022-09-26T21:33:21.000Z (over 3 years ago)
- Last Synced: 2025-04-03T22:08:41.197Z (11 months ago)
- Language: Java
- Size: 173 KB
- Stars: 107
- Watchers: 12
- Forks: 35
- Open Issues: 0
-
Metadata Files:
- Readme: README.markdown
- Changelog: ChangeLog.txt
- Contributing: CONTRIBUTING.markdown
- License: LICENSE.txt
Awesome Lists containing this project
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 3.1.0.RELEASE** - for Thymeleaf 3.0 (requires Thymeleaf 3.0.0+)
* **Version 2.1.0.RELEASE** - for Thymeleaf 2.1 (requires Thymeleaf 2.1.3+)
License
-------
This software is licensed under the [Apache License 2.0]
(http://www.apache.org/licenses/LICENSE-2.0.html).
Requirements (3.0.x)
--------------------
* Java **8**
* Thymeleaf **3.0.0+**
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.

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
* SHORT, MEDIUM, LONG and FULL can also be specified to used the default java.time.format.FormatStyle patterns
* Also works with arrays, lists or sets
*/
${#temporals.format(temporal, 'dd/MMM/yyyy HH:mm')}
${#temporals.format(temporal, 'dd/MMM/yyyy HH:mm', 'Europe/Paris')}
${#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
```