Class DateTimeUtilFormat
strftime formatting for java.time and legacy date types.
The conversions are produced by Strftime, a port of the glibc engine, so the output
matches a C library byte for byte wherever the JDK exposes the same locale data. See that class
for the three places where it cannot and what it does instead.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic StringFormats a supported date-timevalueforFmtand similar APIs.static Stringstatic Stringstatic Stringstatic Stringstatic Stringstrftime(Locale locale, LocalDateTime ldt, String pattern) ldtinterpreted as local clock in the system default zone, thenstrftime(Locale, ZonedDateTime, String).static Stringstrftime(Locale locale, LocalDateTime ldt, ZoneId zone, String pattern) static Stringstrftime(Locale locale, OffsetDateTime odt, String pattern) Same asstrftime(Locale, ZonedDateTime, String)usingodtat the same instant in the system default time zone.static Stringstrftime(Locale locale, OffsetDateTime odt, ZoneId zone, String pattern) static Stringstrftime(Locale locale, ZonedDateTime zdt, String pattern) Formats a date-time using POSIXstrftimeconversion specifiers.static StringSame asstrftime(Locale, ZonedDateTime, String)using the calendar instant in the system default time zone (same instant on the time-line).static Stringstatic Stringstatic Stringstatic voidstrftimeTo(Appendable out, Locale locale, Object value, String pattern) Formatsvaluestraight intoout, for callers that already hold the buffer the result is headed for.
-
Constructor Details
-
DateTimeUtilFormat
public DateTimeUtilFormat()
-
-
Method Details
-
strftime
Formats a date-time using POSIXstrftimeconversion specifiers.A specifier is
'%', an optional flag out of- _ 0 + ^ #, an optional minimum field width, an optionalEorOmodifier, and the conversion character. The POSIX set%a %A %b %B %c %C %d %D %e %F %g %G %h %H %I %j %m %M %n %p %r %R %S %t %T %u %U %V %w %W %x %X %y %Y %z %Z %%is supported, as are the GNU extensions%k %l %P %s. An unknown conversion is echoed back literally, including the'%', as glibc does.Eselects the locale's alternative calendar, which the JDK provides for locales carrying acaextension such asja-JP-u-ca-japanese;Oselects the locale's alternative digits. Where the locale has neither, the conversion behaves as if the modifier were absent, which is what POSIX requires.%zis the offset from UTC in ISO 8601 basic form±hhmm(no colon).%Zis the time-zone abbreviation or short name from the JDK formatter patternz.%cfollows the common C-library layout%a %b %e %H:%M:%S %Y, while%xand%Xare localized. Week-based specifiers%g %G %Vfollow ISO week date rules.- Parameters:
locale- locale for localized elements; must not benullzdt- the zoned date-time, ornull(treated as the literal string"null")pattern- format string with%conversions; must not benull- Returns:
- formatted string
-
strftime
-
strftime
-
strftime
Same asstrftime(Locale, ZonedDateTime, String)usingodtat the same instant in the system default time zone. -
strftime
-
strftime
-
strftime
-
strftime
Same asstrftime(Locale, ZonedDateTime, String)using the calendar instant in the system default time zone (same instant on the time-line). -
strftime
-
strftime
ldtinterpreted as local clock in the system default zone, thenstrftime(Locale, ZonedDateTime, String). -
strftime
-
strftime
-
strftime
-
strftime
Formats a supported date-timevalueforFmtand similar APIs.ZonedDateTimeis left unchanged;OffsetDateTimekeeps its fixed offset. All other supported types are interpreted in the system default zone.Supported types:
ZonedDateTime,OffsetDateTime,Instant,Date,Calendar,LocalDateTime,LocalDate,LocalTime,OffsetTime,Year,YearMonth. Anullvalue yields the literal"null"; an unsupported type throwsFormatException. -
strftimeTo
Formatsvaluestraight intoout, for callers that already hold the buffer the result is headed for.- Throws:
FormatException- ifvalueis of an unsupported type- See Also:
-