< prev index next >

src/java.base/share/classes/java/time/format/DateTimeFormatter.java

Print this page




1121     static {
1122         ISO_WEEK_DATE = new DateTimeFormatterBuilder()
1123                 .parseCaseInsensitive()
1124                 .appendValue(IsoFields.WEEK_BASED_YEAR, 4, 10, SignStyle.EXCEEDS_PAD)
1125                 .appendLiteral("-W")
1126                 .appendValue(IsoFields.WEEK_OF_WEEK_BASED_YEAR, 2)
1127                 .appendLiteral('-')
1128                 .appendValue(DAY_OF_WEEK, 1)
1129                 .optionalStart()
1130                 .appendOffsetId()
1131                 .toFormatter(ResolverStyle.STRICT, IsoChronology.INSTANCE);
1132     }
1133 
1134     //-----------------------------------------------------------------------
1135     /**
1136      * The ISO instant formatter that formats or parses an instant in UTC,
1137      * such as '2011-12-03T10:15:30Z'.
1138      * <p>
1139      * This returns an immutable formatter capable of formatting and parsing
1140      * the ISO-8601 instant format.
1141      * When formatting, the second-of-minute is always output.

1142      * The nano-of-second outputs zero, three, six or nine digits as necessary.
1143      * When parsing, time to at least the seconds field is required.


1144      * Fractional seconds from zero to nine are parsed.
1145      * The localized decimal style is not used.
1146      * <p>
1147      * This is a special case formatter intended to allow a human readable form
1148      * of an {@link java.time.Instant}. The {@code Instant} class is designed to
1149      * only represent a point in time and internally stores a value in nanoseconds
1150      * from a fixed epoch of 1970-01-01Z. As such, an {@code Instant} cannot be
1151      * formatted as a date or time without providing some form of time-zone.
1152      * This formatter allows the {@code Instant} to be formatted, by providing
1153      * a suitable conversion using {@code ZoneOffset.UTC}.
1154      * <p>
1155      * The format consists of:
1156      * <ul>
1157      * <li>The {@link #ISO_OFFSET_DATE_TIME} where the instant is converted from
1158      *  {@link ChronoField#INSTANT_SECONDS} and {@link ChronoField#NANO_OF_SECOND}
1159      *  using the {@code UTC} offset. Parsing is case insensitive.
1160      * </ul>
1161      * <p>
1162      * The returned formatter has no override chronology or zone.
1163      * It uses the {@link ResolverStyle#STRICT STRICT} resolver style.




1121     static {
1122         ISO_WEEK_DATE = new DateTimeFormatterBuilder()
1123                 .parseCaseInsensitive()
1124                 .appendValue(IsoFields.WEEK_BASED_YEAR, 4, 10, SignStyle.EXCEEDS_PAD)
1125                 .appendLiteral("-W")
1126                 .appendValue(IsoFields.WEEK_OF_WEEK_BASED_YEAR, 2)
1127                 .appendLiteral('-')
1128                 .appendValue(DAY_OF_WEEK, 1)
1129                 .optionalStart()
1130                 .appendOffsetId()
1131                 .toFormatter(ResolverStyle.STRICT, IsoChronology.INSTANCE);
1132     }
1133 
1134     //-----------------------------------------------------------------------
1135     /**
1136      * The ISO instant formatter that formats or parses an instant in UTC,
1137      * such as '2011-12-03T10:15:30Z'.
1138      * <p>
1139      * This returns an immutable formatter capable of formatting and parsing
1140      * the ISO-8601 instant format.
1141      * When formatting, the instant will always be suffixed by 'Z' to indicate UTC.
1142      * The second-of-minute is always output.
1143      * The nano-of-second outputs zero, three, six or nine digits as necessary.
1144      * When parsing, the behaviour of {@link DateTimeFormatterBuilder#appendOffsetId()} will be used to
1145      * parse the offset, converting the instant to UTC as necessary.
1146      * The time to at least the seconds field is required.
1147      * Fractional seconds from zero to nine are parsed.
1148      * The localized decimal style is not used.
1149      * <p>
1150      * This is a special case formatter intended to allow a human readable form
1151      * of an {@link java.time.Instant}. The {@code Instant} class is designed to
1152      * only represent a point in time and internally stores a value in nanoseconds
1153      * from a fixed epoch of 1970-01-01Z. As such, an {@code Instant} cannot be
1154      * formatted as a date or time without providing some form of time-zone.
1155      * This formatter allows the {@code Instant} to be formatted, by providing
1156      * a suitable conversion using {@code ZoneOffset.UTC}.
1157      * <p>
1158      * The format consists of:
1159      * <ul>
1160      * <li>The {@link #ISO_OFFSET_DATE_TIME} where the instant is converted from
1161      *  {@link ChronoField#INSTANT_SECONDS} and {@link ChronoField#NANO_OF_SECOND}
1162      *  using the {@code UTC} offset. Parsing is case insensitive.
1163      * </ul>
1164      * <p>
1165      * The returned formatter has no override chronology or zone.
1166      * It uses the {@link ResolverStyle#STRICT STRICT} resolver style.


< prev index next >