欢迎您访问 最编程 本站为您分享编程语言代码,编程技术文章!
您现在的位置是: 首页

在Spring Boot和Thymeleaf中如何轻松处理JSR 310的新日期和时间类型(如LocalDateTime和LocalDate)

最编程 2024-08-03 20:47:43
...
/* * ============================================================================= * 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.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

推荐阅读