Class Iso8601Format

java.lang.Object
net.time4j.format.expert.Iso8601Format

public class Iso8601Format extends Object

Collection of predefined format objects for ISO-8601.

All formatters are strict by default. The preferred decimal separator is the comma during printing. This configuration follows the official recommendation of ISO-8601. However, if the system property "net.time4j.format.iso.decimal.dot" is set to "true" then the dot will be used. When parsing, both comma or dot are understood.

Note: Most produced formatters ignore any format attribute change. As exception case, timezone attributes are recognized by BASIC_DATE_TIME_OFFSET or EXTENDED_DATE_TIME_OFFSET.

Author:
Meno Hochschild
  • Field Details

    • BASIC_CALENDAR_DATE

      public static final ChronoFormatter<PlainDate> BASIC_CALENDAR_DATE

      Defines the basic ISO-8601-format with year, month and day of month using the pattern "uuuuMMdd".

    • EXTENDED_CALENDAR_DATE

      public static final ChronoFormatter<PlainDate> EXTENDED_CALENDAR_DATE

      Defines the extended ISO-8601-format with year, month and day of month using the pattern "uuuu-MM-dd".

    • BASIC_ORDINAL_DATE

      public static final ChronoFormatter<PlainDate> BASIC_ORDINAL_DATE

      Defines the basic ISO-8601-format with year and day of year using the pattern "uuuuDDD".

    • EXTENDED_ORDINAL_DATE

      public static final ChronoFormatter<PlainDate> EXTENDED_ORDINAL_DATE

      Defines the extended ISO-8601-format with year and day of year using the pattern "uuuu-DDD".

    • BASIC_WEEK_DATE

      public static final ChronoFormatter<PlainDate> BASIC_WEEK_DATE

      Defines the basic ISO-8601-format for a week date using the pattern "YYYYWwwE".

    • EXTENDED_WEEK_DATE

      public static final ChronoFormatter<PlainDate> EXTENDED_WEEK_DATE

      Defines the extended ISO-8601-format for a week date using the pattern "YYYY-Www-E".

    • BASIC_DATE

      public static final ChronoFormatter<PlainDate> BASIC_DATE

      Similar to BASIC_CALENDAR_DATE but its parser can also understand ordinal dates or week dates.

      Since:
      3.22/4.18
    • EXTENDED_DATE

      public static final ChronoFormatter<PlainDate> EXTENDED_DATE

      Similar to EXTENDED_CALENDAR_DATE but its parser can also understand ordinal dates or week dates.

      Since:
      3.22/4.18
    • BASIC_WALL_TIME

      public static final ChronoFormatter<PlainTime> BASIC_WALL_TIME

      Defines the basic ISO-8601-format for a wall time with hour, minute and optional second using the pattern "HH[mm[ss[,SSSSSSSSS]]]".

      The minute part is optional during parsing, but will always be printed. The parser also accepts a leading char T.

    • EXTENDED_WALL_TIME

      public static final ChronoFormatter<PlainTime> EXTENDED_WALL_TIME

      Defines the extended ISO-8601-format for a wall time with hour, minute and optional second using the pattern "HH[:mm[:ss[,SSSSSSSSS]]]".

      The minute part is optional during parsing, but will always be printed. The parser also accepts a leading char T.

    • BASIC_DATE_TIME

      public static final ChronoFormatter<PlainTimestamp> BASIC_DATE_TIME

      Defines the basic ISO-8601-format for a composition of calendar date and wall time with hour and minute using the pattern "uuuuMMdd'T'HH[mm[ss[,SSSSSSSSS]]]".

      Second and nanosecond elements are optional. Furthermore, the count of decimal digits is flexible (0-9). The minute part is optional during parsing, but will always be printed. The parser will also understand a combination of ordinal date or week date together with the wall time.

    • EXTENDED_DATE_TIME

      public static final ChronoFormatter<PlainTimestamp> EXTENDED_DATE_TIME

      Defines the extended ISO-8601-format for a composition of calendar date and wall time with hour and minute using the pattern "uuuu-MM-dd'T'HH[:mm[:ss[,SSSSSSSSS]]]".

      Second and nanosecond elements are optional. Furthermore, the count of decimal digits is flexible (0-9). The minute part is optional during parsing, but will always be printed. The parser will also understand a combination of ordinal date or week date together with the wall time.

    • BASIC_DATE_TIME_OFFSET

      public static final ChronoFormatter<Moment> BASIC_DATE_TIME_OFFSET

      Defines the basic ISO-8601-format for a composition of calendar date, wall time and timezone offset using the pattern "uuuuMMdd'T'HH[mm[ss[,SSSSSSSSS]]]{offset}".

      Second and nanosecond elements are optional. Furthermore, the count of decimal digits is flexible (0-9). The minute part is optional during parsing, but will always be printed. The offset part is for printing equivalent to XX, for parsing equivalent to X. The parser will also understand a combination of ordinal date or week date together with the wall time.

      By default, the timezone offset used for printing is UTC+00:00. Users can override this offset by calling the method ChronoFormatter.withTimezone(net.time4j.tz.TZID).

    • EXTENDED_DATE_TIME_OFFSET

      public static final ChronoFormatter<Moment> EXTENDED_DATE_TIME_OFFSET

      Defines the extended ISO-8601-format for a composition of calendar date, wall time and timezone offset using the pattern "uuuu-MM-dd'T'HH[:mm[:ss[,SSSSSSSSS]]]{offset}".

      Second and nanosecond elements are optional. Furthermore, the count of decimal digits is flexible (0-9). The minute part is optional during parsing, but will always be printed. The offset part is for printing equivalent to XXX, for parsing equivalent to X (but with colon!). The parser will also understand a combination of ordinal date or week date together with the wall time.

      By default, the timezone offset used for printing is UTC+00:00. Users can override this offset by calling the method ChronoFormatter.withTimezone(net.time4j.tz.TZID).

  • Method Details

    • ofDate

      public static ChronoPrinter<PlainDate> ofDate(IsoDateStyle style)

      Obtains a printer with given styles for printing a calendar date.

      Parameters:
      style - iso-compatible date style
      Returns:
      ChronoPrinter
      Since:
      4.18
    • ofBasicTime

      public static ChronoPrinter<PlainTime> ofBasicTime(IsoDecimalStyle decimalStyle, ClockUnit precision)

      Obtains a printer with given decimal style for printing a clock time in basic format "HHmm[ss[,SSSSSSSSS]]".

      It is recommended to store the result in a static final constant for achieving best performance.

      Parameters:
      decimalStyle - iso-compatible decimal style
      precision - controls the precision of output format with constant length
      Returns:
      ChronoPrinter as new instance
      Since:
      4.18
    • ofExtendedTime

      public static ChronoPrinter<PlainTime> ofExtendedTime(IsoDecimalStyle decimalStyle, ClockUnit precision)

      Obtains a printer with given decimal style for printing a clock time in extended format "HH:mm[:ss[,SSSSSSSSS]]".

      It is recommended to store the result in a static final constant for achieving best performance.

      Parameters:
      decimalStyle - iso-compatible decimal style
      precision - controls the precision of output format with constant length
      Returns:
      ChronoPrinter as new instance
      Since:
      4.18
    • ofTimestamp

      public static ChronoPrinter<PlainTimestamp> ofTimestamp(IsoDateStyle dateStyle, IsoDecimalStyle decimalStyle, ClockUnit precision)

      Obtains a printer with given styles for printing a timestamp.

      It is recommended to store the result in a static final constant for achieving best performance.

      Parameters:
      dateStyle - iso-compatible date style
      decimalStyle - iso-compatible decimal style
      precision - controls the precision of output format with constant length
      Returns:
      ChronoPrinter as new instance
      Since:
      4.18
    • ofMoment

      public static ChronoPrinter<Moment> ofMoment(IsoDateStyle dateStyle, IsoDecimalStyle decimalStyle, ClockUnit precision, ZonalOffset offset)

      Obtains a printer with given styles for printing a moment.

      It is recommended to store the result in a static final constant for achieving best performance.

      Parameters:
      dateStyle - iso-compatible date style
      decimalStyle - iso-compatible decimal style
      precision - controls the precision of output format with constant length
      offset - time zone offset
      Returns:
      ChronoPrinter as new instance
      Since:
      4.18
    • parseDate

      public static PlainDate parseDate(CharSequence iso) throws ParseException

      Parses given ISO-8601-compatible date string in basic or extended format.

      Parameters:
      iso - text like "20160101", "2016001", "2016W011", "2016-01-01", "2016-001" or "2016-W01-1"
      Returns:
      PlainDate
      Throws:
      ParseException - if parsing fails for any reason
      Since:
      3.22/4.18
    • parseDate

      public static PlainDate parseDate(CharSequence iso, ParseLog plog)

      Parses given ISO-8601-compatible date string in basic or extended format.

      Parameters:
      iso - text like "20160101", "2016001", "2016W011", "2016-01-01", "2016-001" or "2016-W01-1"
      plog - new mutable instance of ParseLog
      Returns:
      PlainDate or null in case of error
      Throws:
      IndexOutOfBoundsException - if the start position is at end of text or even behind
      Since:
      3.22/4.18
      See Also:
      ParseLog.isError()