• Stars
    star
    107
  • Rank 323,587 (Top 7 %)
  • Language
    Java
  • License
    Apache License 2.0
  • Created almost 10 years ago
  • Updated about 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Thymeleaf "extras" dialect for formatting and creating Java 8 Time API objects

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.

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.

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

Usage

/*
 * =============================================================================
 * 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

More Repositories

1

thymeleaf

Thymeleaf is a modern server-side Java template engine for both web and standalone environments.
Java
2,776
star
2

thymeleaf-extras-springsecurity

Thymeleaf "extras" integration module for Spring Security 3.x and 4.x
Java
476
star
3

thymeleaf-spring

Thymeleaf integration module for Spring
Java
432
star
4

thymeleafexamples-gtvg

Good Thymes Virtual Grocery - Companion application for the "Using Thymeleaf" tutorial downloadable at the Thymeleaf website: http://www.thymeleaf.org/documentation.html
Java
290
star
5

thymeleafexamples-layouts

Layouts - Companion application for the "Thymeleaf Layouts" article at the Thymeleaf website: http://www.thymeleaf.org/documentation.html http://www.thymeleaf.org
Java
245
star
6

thymeleafexamples-stsm

Spring Thyme Seedstarter Manager - Companion application for the "Thymeleaf + Spring 3" tutorial downloadable at the Thymeleaf website: http://www.thymeleaf.org/documentation.html
Java
184
star
7

thymeleafexamples-petclinic

Spring PetClinic + Thymeleaf- Companion application for the "Bringing Thymeleaf and Natural Templates to the Spring PetClinic" article at the Thymeleaf website: http://www.thymeleaf.org/doc/articles/petclinic.html
Java
154
star
8

thymeleaf-extras-eclipse-plugin

Thymeleaf integration plugin for the Eclipse IDE
Groovy
132
star
9

thymeleafexamples-springmail

SpringMail - Companion application for the "Rich HTML email in Spring with Thymeleaf" article at the Thymeleaf website: http://www.thymeleaf.org/doc/articles/springmail.html
Java
112
star
10

thymeleaf-testing

Thymeleaf testing infrastructure
Java
77
star
11

thymeleafexamples-springsecurity

SpringSecurity - Companion application for the "Login and error pages using Thymeleaf and Spring Security" article at the Thymeleaf website: http://www.thymeleaf.org/springsecurity.html
Java
66
star
12

thymeleaf-itutorial

Thymeleaf interactive tutorial
HTML
45
star
13

thymeleaf-docs

Thymeleaf documentation
CSS
44
star
14

thymeleaf-extras-tiles2

Thymeleaf integration with Apache Tiles 2.x
Java
35
star
15

thymeleafsandbox-biglist-reactive

Sandbox application testing the render of large amounts of markup using Thymeleaf with Spring Web Reactive
Java
32
star
16

thymeleaf-tests

Thymeleaf test suite
Java
30
star
17

thymeleaf-dist

Thymeleaf artifacts for distribution files, documentation and website management
HTML
26
star
18

thymeleafexamples-extrathyme

ExtraThyme - Companion application for the "Extending Thymeleaf" tutorial downloadable at the Thymeleaf website: http://www.thymeleaf.org/documentation.html
Java
24
star
19

thymeleaf-extras-conditionalcomments

Thymeleaf "extras" dialect for correctly processing IE conditional comments (for Thymeleaf 2.x)
Java
20
star
20

thymeleafexamples-thvsjsp

Thymeleaf vs JSP - Companion application for the "Spring MVC view layer: Thymeleaf vs. JSP" article at the Thymeleaf website: http://www.thymeleaf.org/thvsjsp.html
Java
17
star
21

thymeleaf.github.io

Thymeleaf website
HTML
14
star
22

thymeleafsandbox-sse-webflux

SSE (Server-Sent Events) example application using Spring 5.0, Spring WebFlux and Spring Boot 2.0 Edit Add topics
Java
14
star
23

thymeleafsandbox-stsm-reactive

Version of the STSM example application using Spring 5.0, Spring Web Reactive and Spring Boot 2.0
Java
8
star
24

thymeleafexamples-sayhello

Say Hello! - Companion application for the "Say Hello! Extending Thymeleaf in 5 minutes" article at the Thymeleaf website: http://www.thymeleaf.org/sayhelloextendingthymeleaf5minutes.html
Java
8
star
25

thymeleaf-tools

Misc tools for helping thymeleaf development
Java
5
star
26

thymeleafsandbox-springsecurity-mvc

Java
4
star
27

thymeleafsandbox-stsm-mvc

Java
3
star
28

thymeleaf-benchmarks

Thymeleaf Development Benchmarks
Java
3
star
29

thymeleafsandbox-springsecurity-reactive

Java
2
star
30

thymeleafsandbox-biglist-mvc

Sandbox application testing the render of large amounts of markup using Thymeleaf with Spring Web MVC
Java
2
star
31

thymeleafsandbox-springjsp

Spring + JSP sandbox application. Only for internal development use by the Thymeleaf team.
Java
1
star