906 ISO_LOCAL_DATE_TIME = new DateTimeFormatterBuilder() 907 .parseCaseInsensitive() 908 .append(ISO_LOCAL_DATE) 909 .appendLiteral('T') 910 .append(ISO_LOCAL_TIME) 911 .toFormatter(ResolverStyle.STRICT, IsoChronology.INSTANCE); 912 } 913 914 //----------------------------------------------------------------------- 915 /** 916 * The ISO date-time formatter that formats or parses a date-time with an 917 * offset, such as '2011-12-03T10:15:30+01:00'. 918 * <p> 919 * This returns an immutable formatter capable of formatting and parsing 920 * the ISO-8601 extended offset date-time format. 921 * The format consists of: 922 * <ul> 923 * <li>The {@link #ISO_LOCAL_DATE_TIME} 924 * <li>The {@link ZoneOffset#getId() offset ID}. If the offset has seconds then 925 * they will be handled even though this is not part of the ISO-8601 standard. 926 * Parsing is case insensitive. 927 * </ul> 928 * <p> 929 * The returned formatter has a chronology of ISO set to ensure dates in 930 * other calendar systems are correctly converted. 931 * It has no override zone and uses the {@link ResolverStyle#STRICT STRICT} resolver style. 932 */ 933 public static final DateTimeFormatter ISO_OFFSET_DATE_TIME; 934 static { 935 ISO_OFFSET_DATE_TIME = new DateTimeFormatterBuilder() 936 .parseCaseInsensitive() 937 .append(ISO_LOCAL_DATE_TIME) 938 .appendOffsetId() 939 .toFormatter(ResolverStyle.STRICT, IsoChronology.INSTANCE); 940 } 941 942 //----------------------------------------------------------------------- 943 /** 944 * The ISO-like date-time formatter that formats or parses a date-time with 945 * offset and zone, such as '2011-12-03T10:15:30+01:00[Europe/Paris]'. 946 * <p> 947 * This returns an immutable formatter capable of formatting and parsing 948 * a format that extends the ISO-8601 extended offset date-time format 949 * to add the time-zone. 950 * The section in square brackets is not part of the ISO-8601 standard. 951 * The format consists of: 952 * <ul> 953 * <li>The {@link #ISO_OFFSET_DATE_TIME} 954 * <li>If the zone ID is not available or is a {@code ZoneOffset} then the format is complete. 955 * <li>An open square bracket '['. 956 * <li>The {@link ZoneId#getId() zone ID}. This is not part of the ISO-8601 standard. 957 * Parsing is case sensitive. 958 * <li>A close square bracket ']'. 1143 } 1144 1145 //----------------------------------------------------------------------- 1146 /** 1147 * The ISO date formatter that formats or parses a date without an 1148 * offset, such as '20111203'. 1149 * <p> 1150 * This returns an immutable formatter capable of formatting and parsing 1151 * the ISO-8601 basic local date format. 1152 * The format consists of: 1153 * <ul> 1154 * <li>Four digits for the {@link ChronoField#YEAR year}. 1155 * Only years in the range 0000 to 9999 are supported. 1156 * <li>Two digits for the {@link ChronoField#MONTH_OF_YEAR month-of-year}. 1157 * This is pre-padded by zero to ensure two digits. 1158 * <li>Two digits for the {@link ChronoField#DAY_OF_MONTH day-of-month}. 1159 * This is pre-padded by zero to ensure two digits. 1160 * <li>If the offset is not available to format or parse then the format is complete. 1161 * <li>The {@link ZoneOffset#getId() offset ID} without colons. If the offset has 1162 * seconds then they will be handled even though this is not part of the ISO-8601 standard. 1163 * Parsing is case insensitive. 1164 * </ul> 1165 * <p> 1166 * As this formatter has an optional element, it may be necessary to parse using 1167 * {@link DateTimeFormatter#parseBest}. 1168 * <p> 1169 * The returned formatter has a chronology of ISO set to ensure dates in 1170 * other calendar systems are correctly converted. 1171 * It has no override zone and uses the {@link ResolverStyle#STRICT STRICT} resolver style. 1172 */ 1173 public static final DateTimeFormatter BASIC_ISO_DATE; 1174 static { 1175 BASIC_ISO_DATE = new DateTimeFormatterBuilder() 1176 .parseCaseInsensitive() 1177 .appendValue(YEAR, 4) 1178 .appendValue(MONTH_OF_YEAR, 2) 1179 .appendValue(DAY_OF_MONTH, 2) 1180 .optionalStart() 1181 .appendOffset("+HHMMss", "Z") 1182 .toFormatter(ResolverStyle.STRICT, IsoChronology.INSTANCE); 1183 } 1184 1185 //----------------------------------------------------------------------- 1186 /** 1187 * The RFC-1123 date-time formatter, such as 'Tue, 3 Jun 2008 11:05:30 GMT'. 1188 * <p> 1189 * This returns an immutable formatter capable of formatting and parsing 1190 * most of the RFC-1123 format. 1191 * RFC-1123 updates RFC-822 changing the year from two digits to four. 1192 * This implementation requires a four digit year. 1193 * This implementation also does not handle North American or military zone 1194 * names, only 'GMT' and offset amounts. 1195 * <p> 1196 * The format consists of: 1197 * <ul> 1198 * <li>If the day-of-week is not available to format or parse then jump to day-of-month. 1199 * <li>Three letter {@link ChronoField#DAY_OF_WEEK day-of-week} in English. 1200 * <li>A comma 1201 * <li>A space | 906 ISO_LOCAL_DATE_TIME = new DateTimeFormatterBuilder() 907 .parseCaseInsensitive() 908 .append(ISO_LOCAL_DATE) 909 .appendLiteral('T') 910 .append(ISO_LOCAL_TIME) 911 .toFormatter(ResolverStyle.STRICT, IsoChronology.INSTANCE); 912 } 913 914 //----------------------------------------------------------------------- 915 /** 916 * The ISO date-time formatter that formats or parses a date-time with an 917 * offset, such as '2011-12-03T10:15:30+01:00'. 918 * <p> 919 * This returns an immutable formatter capable of formatting and parsing 920 * the ISO-8601 extended offset date-time format. 921 * The format consists of: 922 * <ul> 923 * <li>The {@link #ISO_LOCAL_DATE_TIME} 924 * <li>The {@link ZoneOffset#getId() offset ID}. If the offset has seconds then 925 * they will be handled even though this is not part of the ISO-8601 standard. 926 * The offset parsing is lenient, which allows the minutes and seconds to be optional. 927 * Parsing is case insensitive. 928 * </ul> 929 * <p> 930 * The returned formatter has a chronology of ISO set to ensure dates in 931 * other calendar systems are correctly converted. 932 * It has no override zone and uses the {@link ResolverStyle#STRICT STRICT} resolver style. 933 */ 934 public static final DateTimeFormatter ISO_OFFSET_DATE_TIME; 935 static { 936 ISO_OFFSET_DATE_TIME = new DateTimeFormatterBuilder() 937 .parseCaseInsensitive() 938 .append(ISO_LOCAL_DATE_TIME) 939 .parseLenient() 940 .appendOffsetId() 941 .parseStrict() 942 .toFormatter(ResolverStyle.STRICT, IsoChronology.INSTANCE); 943 } 944 945 //----------------------------------------------------------------------- 946 /** 947 * The ISO-like date-time formatter that formats or parses a date-time with 948 * offset and zone, such as '2011-12-03T10:15:30+01:00[Europe/Paris]'. 949 * <p> 950 * This returns an immutable formatter capable of formatting and parsing 951 * a format that extends the ISO-8601 extended offset date-time format 952 * to add the time-zone. 953 * The section in square brackets is not part of the ISO-8601 standard. 954 * The format consists of: 955 * <ul> 956 * <li>The {@link #ISO_OFFSET_DATE_TIME} 957 * <li>If the zone ID is not available or is a {@code ZoneOffset} then the format is complete. 958 * <li>An open square bracket '['. 959 * <li>The {@link ZoneId#getId() zone ID}. This is not part of the ISO-8601 standard. 960 * Parsing is case sensitive. 961 * <li>A close square bracket ']'. 1146 } 1147 1148 //----------------------------------------------------------------------- 1149 /** 1150 * The ISO date formatter that formats or parses a date without an 1151 * offset, such as '20111203'. 1152 * <p> 1153 * This returns an immutable formatter capable of formatting and parsing 1154 * the ISO-8601 basic local date format. 1155 * The format consists of: 1156 * <ul> 1157 * <li>Four digits for the {@link ChronoField#YEAR year}. 1158 * Only years in the range 0000 to 9999 are supported. 1159 * <li>Two digits for the {@link ChronoField#MONTH_OF_YEAR month-of-year}. 1160 * This is pre-padded by zero to ensure two digits. 1161 * <li>Two digits for the {@link ChronoField#DAY_OF_MONTH day-of-month}. 1162 * This is pre-padded by zero to ensure two digits. 1163 * <li>If the offset is not available to format or parse then the format is complete. 1164 * <li>The {@link ZoneOffset#getId() offset ID} without colons. If the offset has 1165 * seconds then they will be handled even though this is not part of the ISO-8601 standard. 1166 * The offset parsing is lenient, which allows the minutes and seconds to be optional. 1167 * Parsing is case insensitive. 1168 * </ul> 1169 * <p> 1170 * As this formatter has an optional element, it may be necessary to parse using 1171 * {@link DateTimeFormatter#parseBest}. 1172 * <p> 1173 * The returned formatter has a chronology of ISO set to ensure dates in 1174 * other calendar systems are correctly converted. 1175 * It has no override zone and uses the {@link ResolverStyle#STRICT STRICT} resolver style. 1176 */ 1177 public static final DateTimeFormatter BASIC_ISO_DATE; 1178 static { 1179 BASIC_ISO_DATE = new DateTimeFormatterBuilder() 1180 .parseCaseInsensitive() 1181 .appendValue(YEAR, 4) 1182 .appendValue(MONTH_OF_YEAR, 2) 1183 .appendValue(DAY_OF_MONTH, 2) 1184 .optionalStart() 1185 .parseLenient() 1186 .appendOffset("+HHMMss", "Z") 1187 .parseStrict() 1188 .toFormatter(ResolverStyle.STRICT, IsoChronology.INSTANCE); 1189 } 1190 1191 //----------------------------------------------------------------------- 1192 /** 1193 * The RFC-1123 date-time formatter, such as 'Tue, 3 Jun 2008 11:05:30 GMT'. 1194 * <p> 1195 * This returns an immutable formatter capable of formatting and parsing 1196 * most of the RFC-1123 format. 1197 * RFC-1123 updates RFC-822 changing the year from two digits to four. 1198 * This implementation requires a four digit year. 1199 * This implementation also does not handle North American or military zone 1200 * names, only 'GMT' and offset amounts. 1201 * <p> 1202 * The format consists of: 1203 * <ul> 1204 * <li>If the day-of-week is not available to format or parse then jump to day-of-month. 1205 * <li>Three letter {@link ChronoField#DAY_OF_WEEK day-of-week} in English. 1206 * <li>A comma 1207 * <li>A space |