|
19 | 19 | import java.text.DateFormat; |
20 | 20 | import java.text.DecimalFormat; |
21 | 21 | import java.text.NumberFormat; |
22 | | -import java.time.LocalDate; |
23 | | -import java.time.LocalDateTime; |
24 | | -import java.time.LocalTime; |
| 22 | +import java.time.*; |
25 | 23 | import java.time.format.DateTimeFormatter; |
26 | 24 | import java.time.temporal.TemporalAccessor; |
27 | 25 | import java.util.Date; |
@@ -312,4 +310,43 @@ public static String formatDate(Date date, String pattern, java.util.Locale loca |
312 | 310 | */ |
313 | 311 | private Formatters() { |
314 | 312 | } |
| 313 | + |
| 314 | + /** |
| 315 | + * Formats a {@link ZonedDateTime} object as an ISO zoned date-time string. |
| 316 | + * |
| 317 | + * @param zonedDateTime the zoned date-time to format |
| 318 | + * @return the formatted ISO zoned date-time string |
| 319 | + */ |
| 320 | + public static String formatZonedDateTime(ZonedDateTime zonedDateTime) { |
| 321 | + if (zonedDateTime == null) { |
| 322 | + return ""; |
| 323 | + } |
| 324 | + return zonedDateTime.format(DateTimeFormatter.ISO_ZONED_DATE_TIME); |
| 325 | + } |
| 326 | + |
| 327 | + /** |
| 328 | + * Formats an {@link OffsetDateTime} object as an ISO offset date-time string. |
| 329 | + * |
| 330 | + * @param offsetDateTime the offset date-time to format |
| 331 | + * @return the formatted ISO offset date-time string |
| 332 | + */ |
| 333 | + public static String formatOffsetDateTime(OffsetDateTime offsetDateTime) { |
| 334 | + if (offsetDateTime == null) { |
| 335 | + return ""; |
| 336 | + } |
| 337 | + return offsetDateTime.format(DateTimeFormatter.ISO_OFFSET_DATE_TIME); |
| 338 | + } |
| 339 | + |
| 340 | + /** |
| 341 | + * Formats an {@link Instant} object as an ISO offset date-time string in the default time zone. |
| 342 | + * |
| 343 | + * @param instant the instant to format |
| 344 | + * @return the formatted ISO offset date-time string |
| 345 | + */ |
| 346 | + public static String formatInstant(Instant instant) { |
| 347 | + if (instant == null) { |
| 348 | + return ""; |
| 349 | + } |
| 350 | + return instant.atZone(Messages.getDefaultTimeZone()).format(DateTimeFormatter.ISO_OFFSET_DATE_TIME); |
| 351 | + } |
315 | 352 | } |
0 commit comments