1 16 package org.joda.time.format; 17 18 import java.util.Collection ; 19 20 import org.joda.time.DateTimeFieldType; 21 import org.joda.time.DateTimeZone; 22 23 58 public class ISODateTimeFormat { 59 60 private static DateTimeFormatter 62 ye, mye, dme, we, wwe, dwe, dye, hde, mhe, sme, lse, fse, ze, lte, 77 ym, ymd, 81 ww, wwd, 85 hm, hms, hmsl, hmsf, 91 dh, dhm, dhms, dhmsl, dhmsf, 97 t, tx, tt, ttx, dt, dtx, 105 wdt, wdtx, 109 od, odt, odtx, 113 bd, bt, btx, btt, bttx, bdt, bdtx, 121 bod, bodt, bodtx, 125 bwd, bwdt, bwdtx, 129 dpe, tpe, dp, ldp, tp, ltp, dtp, dotp, ldotp; 139 144 protected ISODateTimeFormat() { 145 super(); 146 } 147 148 215 public static DateTimeFormatter forFields( 216 Collection fields, 217 boolean extended, 218 boolean strictISO) { 219 220 if (fields == null || fields.size() == 0) { 221 throw new IllegalArgumentException ("The fields must not be null or empty"); 222 } 223 int inputSize = fields.size(); 224 boolean reducedPrec = false; 225 DateTimeFormatterBuilder bld = new DateTimeFormatterBuilder(); 226 if (fields.contains(DateTimeFieldType.monthOfYear())) { 228 reducedPrec = dateByMonth(bld, fields, extended, strictISO); 229 } else if (fields.contains(DateTimeFieldType.dayOfYear())) { 230 reducedPrec = dateByOrdinal(bld, fields, extended, strictISO); 231 } else if (fields.contains(DateTimeFieldType.weekOfWeekyear())) { 232 reducedPrec = dateByWeek(bld, fields, extended, strictISO); 233 } else if (fields.contains(DateTimeFieldType.dayOfMonth())) { 234 reducedPrec = dateByMonth(bld, fields, extended, strictISO); 235 } else if (fields.contains(DateTimeFieldType.dayOfWeek())) { 236 reducedPrec = dateByWeek(bld, fields, extended, strictISO); 237 } else if (fields.remove(DateTimeFieldType.year())) { 238 bld.append(yearElement()); 239 reducedPrec = true; 240 } else if (fields.remove(DateTimeFieldType.weekyear())) { 241 bld.append(weekyearElement()); 242 reducedPrec = true; 243 } 244 boolean datePresent = (fields.size() < inputSize); 245 246 time(bld, fields, extended, strictISO, reducedPrec, datePresent); 248 249 if (bld.canBuildFormatter() == false) { 251 throw new IllegalArgumentException ("No valid format for fields: " + fields); 252 } 253 return bld.toFormatter(); 254 } 255 256 268 private static boolean dateByMonth( 269 DateTimeFormatterBuilder bld, 270 Collection fields, 271 boolean extended, 272 boolean strictISO) { 273 274 boolean reducedPrec = false; 275 if (fields.remove(DateTimeFieldType.year())) { 276 bld.append(yearElement()); 277 if (fields.remove(DateTimeFieldType.monthOfYear())) { 278 if (fields.remove(DateTimeFieldType.dayOfMonth())) { 279 appendSeparator(bld, extended); 281 bld.appendMonthOfYear(2); 282 appendSeparator(bld, extended); 283 bld.appendDayOfMonth(2); 284 } else { 285 bld.appendLiteral('-'); 287 bld.appendMonthOfYear(2); 288 reducedPrec = true; 289 } 290 } else { 291 if (fields.remove(DateTimeFieldType.dayOfMonth())) { 292 checkNotStrictISO(fields, strictISO); 294 bld.appendLiteral('-'); 295 bld.appendLiteral('-'); 296 bld.appendDayOfMonth(2); 297 } else { 298 reducedPrec = true; 300 } 301 } 302 303 } else if (fields.remove(DateTimeFieldType.monthOfYear())) { 304 bld.appendLiteral('-'); 305 bld.appendLiteral('-'); 306 bld.appendMonthOfYear(2); 307 if (fields.remove(DateTimeFieldType.dayOfMonth())) { 308 appendSeparator(bld, extended); 310 bld.appendDayOfMonth(2); 311 } else { 312 reducedPrec = true; 314 } 315 } else if (fields.remove(DateTimeFieldType.dayOfMonth())) { 316 bld.appendLiteral('-'); 318 bld.appendLiteral('-'); 319 bld.appendLiteral('-'); 320 bld.appendDayOfMonth(2); 321 } 322 return reducedPrec; 323 } 324 325 336 private static boolean dateByOrdinal( 337 DateTimeFormatterBuilder bld, 338 Collection fields, 339 boolean extended, 340 boolean strictISO) { 341 342 boolean reducedPrec = false; 343 if (fields.remove(DateTimeFieldType.year())) { 344 bld.append(yearElement()); 345 if (fields.remove(DateTimeFieldType.dayOfYear())) { 346 appendSeparator(bld, extended); 348 bld.appendDayOfYear(3); 349 } else { 350 reducedPrec = true; 352 } 353 354 } else if (fields.remove(DateTimeFieldType.dayOfYear())) { 355 bld.appendLiteral('-'); 357 bld.appendDayOfYear(3); 358 } 359 return reducedPrec; 360 } 361 362 373 private static boolean dateByWeek( 374 DateTimeFormatterBuilder bld, 375 Collection fields, 376 boolean extended, 377 boolean strictISO) { 378 379 boolean reducedPrec = false; 380 if (fields.remove(DateTimeFieldType.weekyear())) { 381 bld.append(weekyearElement()); 382 if (fields.remove(DateTimeFieldType.weekOfWeekyear())) { 383 appendSeparator(bld, extended); 384 bld.appendLiteral('W'); 385 bld.appendWeekOfWeekyear(2); 386 if (fields.remove(DateTimeFieldType.dayOfWeek())) { 387 appendSeparator(bld, extended); 389 bld.appendDayOfWeek(1); 390 } else { 391 reducedPrec = true; 393 } 394 } else { 395 if (fields.remove(DateTimeFieldType.dayOfWeek())) { 396 checkNotStrictISO(fields, strictISO); 398 appendSeparator(bld, extended); 399 bld.appendLiteral('W'); 400 bld.appendLiteral('-'); 401 bld.appendDayOfWeek(1); 402 } else { 403 reducedPrec = true; 405 } 406 } 407 408 } else if (fields.remove(DateTimeFieldType.weekOfWeekyear())) { 409 bld.appendLiteral('-'); 410 bld.appendLiteral('W'); 411 bld.appendWeekOfWeekyear(2); 412 if (fields.remove(DateTimeFieldType.dayOfWeek())) { 413 appendSeparator(bld, extended); 415 bld.appendDayOfWeek(1); 416 } else { 417 reducedPrec = true; 419 } 420 } else if (fields.remove(DateTimeFieldType.dayOfWeek())) { 421 bld.appendLiteral('-'); 423 bld.appendLiteral('W'); 424 bld.appendLiteral('-'); 425 bld.appendDayOfWeek(1); 426 } 427 return reducedPrec; 428 } 429 430 443 private static void time( 444 DateTimeFormatterBuilder bld, 445 Collection fields, 446 boolean extended, 447 boolean strictISO, 448 boolean reducedPrec, 449 boolean datePresent) { 450 451 boolean hour = fields.remove(DateTimeFieldType.hourOfDay()); 452 boolean minute = fields.remove(DateTimeFieldType.minuteOfHour()); 453 boolean second = fields.remove(DateTimeFieldType.secondOfMinute()); 454 boolean milli = fields.remove(DateTimeFieldType.millisOfSecond()); 455 if (!hour && !minute && !second && !milli) { 456 return; 457 } 458 if (hour || minute || second || milli) { 459 if (strictISO && reducedPrec) { 460 throw new IllegalArgumentException ("No valid ISO8601 format for fields because Date was reduced precision: " + fields); 461 } 462 if (datePresent) { 463 bld.appendLiteral('T'); 464 } 465 } 466 if (hour && minute && second || (hour && !second && !milli)) { 467 } else { 469 if (strictISO && datePresent) { 470 throw new IllegalArgumentException ("No valid ISO8601 format for fields because Time was truncated: " + fields); 471 } 472 if (!hour && (minute && second || (minute && !milli) || second)) { 473 } else { 475 if (strictISO) { 476 throw new IllegalArgumentException ("No valid ISO8601 format for fields: " + fields); 477 } 478 } 479 } 480 if (hour) { 481 bld.appendHourOfDay(2); 482 } else if (minute || second || milli) { 483 bld.appendLiteral('-'); 484 } 485 if (extended && hour && minute) { 486 bld.appendLiteral(':'); 487 } 488 if (minute) { 489 bld.appendMinuteOfHour(2); 490 } else if (second || milli) { 491 bld.appendLiteral('-'); 492 } 493 if (extended && minute && second) { 494 bld.appendLiteral(':'); 495 } 496 if (second) { 497 bld.appendSecondOfMinute(2); 498 } else if (milli) { 499 bld.appendLiteral('-'); 500 } 501 if (milli) { 502 bld.appendLiteral('.'); 503 bld.appendMillisOfSecond(3); 504 } 505 } 506 507 515 private static void checkNotStrictISO(Collection fields, boolean strictISO) { 516 if (strictISO) { 517 throw new IllegalArgumentException ("No valid ISO8601 format for fields: " + fields); 518 } 519 } 520 521 529 private static void appendSeparator(DateTimeFormatterBuilder bld, boolean extended) { 530 if (extended) { 531 bld.appendLiteral('-'); 532 } 533 } 534 535 548 public static DateTimeFormatter dateParser() { 549 if (dp == null) { 550 DateTimeParser tOffset = new DateTimeFormatterBuilder() 551 .appendLiteral('T') 552 .append(offsetElement()).toParser(); 553 dp = new DateTimeFormatterBuilder() 554 .append(dateElementParser()) 555 .appendOptional(tOffset) 556 .toFormatter(); 557 } 558 return dp; 559 } 560 561 574 public static DateTimeFormatter localDateParser() { 575 if (ldp == null) { 576 ldp = dateElementParser().withZone(DateTimeZone.UTC); 577 } 578 return ldp; 579 } 580 581 591 public static DateTimeFormatter dateElementParser() { 592 if (dpe == null) { 593 dpe = new DateTimeFormatterBuilder() 594 .append(null, new DateTimeParser[] { 595 new DateTimeFormatterBuilder() 596 .append(yearElement()) 597 .appendOptional 598 (new DateTimeFormatterBuilder() 599 .append(monthElement()) 600 .appendOptional(dayOfMonthElement().getParser()) 601 .toParser()) 602 .toParser(), 603 new DateTimeFormatterBuilder() 604 .append(weekyearElement()) 605 .append(weekElement()) 606 .appendOptional(dayOfWeekElement().getParser()) 607 .toParser(), 608 new DateTimeFormatterBuilder() 609 .append(yearElement()) 610 .append(dayOfYearElement()) 611 .toParser() 612 }) 613 .toFormatter(); 614 } 615 return dpe; 616 } 617 618 630 public static DateTimeFormatter timeParser() { 631 if (tp == null) { 632 tp = new DateTimeFormatterBuilder() 633 .appendOptional(literalTElement().getParser()) 634 .append(timeElementParser()) 635 .appendOptional(offsetElement().getParser()) 636 .toFormatter(); 637 } 638 return tp; 639 } 640 641 655 public static DateTimeFormatter localTimeParser() { 656 if (ltp == null) { 657 ltp = new DateTimeFormatterBuilder() 658 .appendOptional(literalTElement().getParser()) 659 .append(timeElementParser()) 660 .toFormatter().withZone(DateTimeZone.UTC); 661 } 662 return ltp; 663 } 664 665 675 public static DateTimeFormatter timeElementParser() { 676 if (tpe == null) { 677 DateTimeParser decimalPoint = new DateTimeFormatterBuilder() 679 .append(null, new DateTimeParser[] { 680 new DateTimeFormatterBuilder() 681 .appendLiteral('.') 682 .toParser(), 683 new DateTimeFormatterBuilder() 684 .appendLiteral(',') 685 .toParser() 686 }) 687 .toParser(); 688 689 tpe = new DateTimeFormatterBuilder() 690 .append(hourElement()) 692 .append 693 (null, new DateTimeParser[] { 694 new DateTimeFormatterBuilder() 695 .append(minuteElement()) 697 .append 698 (null, new DateTimeParser[] { 699 new DateTimeFormatterBuilder() 700 .append(secondElement()) 702 .appendOptional(new DateTimeFormatterBuilder() 704 .append(decimalPoint) 705 .appendFractionOfSecond(1, 9) 706 .toParser()) 707 .toParser(), 708 new DateTimeFormatterBuilder() 710 .append(decimalPoint) 711 .appendFractionOfMinute(1, 9) 712 .toParser(), 713 null 714 }) 715 .toParser(), 716 new DateTimeFormatterBuilder() 718 .append(decimalPoint) 719 .appendFractionOfHour(1, 9) 720 .toParser(), 721 null 722 }) 723 .toFormatter(); 724 } 725 return tpe; 726 } 727 728 746 public static DateTimeFormatter dateTimeParser() { 747 if (dtp == null) { 748 DateTimeParser time = new DateTimeFormatterBuilder() 751 .appendLiteral('T') 752 .append(timeElementParser()) 753 .appendOptional(offsetElement().getParser()) 754 .toParser(); 755 dtp = new DateTimeFormatterBuilder() 756 .append(null, new DateTimeParser[] {time, dateOptionalTimeParser().getParser()}) 757 .toFormatter(); 758 } 759 return dtp; 760 } 761 762 779 public static DateTimeFormatter dateOptionalTimeParser() { 780 if (dotp == null) { 781 DateTimeParser timeOrOffset = new DateTimeFormatterBuilder() 782 .appendLiteral('T') 783 .appendOptional(timeElementParser().getParser()) 784 .appendOptional(offsetElement().getParser()) 785 .toParser(); 786 dotp = new DateTimeFormatterBuilder() 787 .append(dateElementParser()) 788 .appendOptional(timeOrOffset) 789 .toFormatter(); 790 } 791 return dotp; 792 } 793 794 813 public static DateTimeFormatter localDateOptionalTimeParser() { 814 if (ldotp == null) { 815 DateTimeParser time = new DateTimeFormatterBuilder() 816 .appendLiteral('T') 817 .append(timeElementParser()) 818 .toParser(); 819 ldotp = new DateTimeFormatterBuilder() 820 .append(dateElementParser()) 821 .appendOptional(time) 822 .toFormatter().withZone(DateTimeZone.UTC); 823 } 824 return ldotp; 825 } 826 827 834 public static DateTimeFormatter date() { 835 return yearMonthDay(); 836 } 837 838 846 public static DateTimeFormatter time() { 847 if (t == null) { 848 t = new DateTimeFormatterBuilder() 849 .append(hourMinuteSecondMillis()) 850 .append(offsetElement()) 851 .toFormatter(); 852 } 853 return t; 854 } 855 856 863 public static DateTimeFormatter timeNoMillis() { 864 if (tx == null) { 865 tx = new DateTimeFormatterBuilder() 866 .append(hourMinuteSecond()) 867 .append(offsetElement()) 868 .toFormatter(); 869 } 870 return tx; 871 } 872 873 881 public static DateTimeFormatter tTime() { 882 if (tt == null) { 883 tt = new DateTimeFormatterBuilder() 884 .append(literalTElement()) 885 .append(time()) 886 .toFormatter(); 887 } 888 return tt; 889 } 890 891 899 public static DateTimeFormatter tTimeNoMillis() { 900 if (ttx == null) { 901 ttx = new DateTimeFormatterBuilder() 902 .append(literalTElement()) 903 .append(timeNoMillis()) 904 .toFormatter(); 905 } 906 return ttx; 907 } 908 909 916 public static DateTimeFormatter dateTime() { 917 if (dt == null) { 918 dt = new DateTimeFormatterBuilder() 919 .append(date()) 920 .append(tTime()) 921 .toFormatter(); 922 } 923 return dt; 924 } 925 926 933 public static DateTimeFormatter dateTimeNoMillis() { 934 if (dtx == null) { 935 dtx = new DateTimeFormatterBuilder() 936 .append(date()) 937 .append(tTimeNoMillis()) 938 .toFormatter(); 939 } 940 return dtx; 941 } 942 943 950 public static DateTimeFormatter ordinalDate() { 951 if (od == null) { 952 od = new DateTimeFormatterBuilder() 953 .append(yearElement()) 954 .append(dayOfYearElement()) 955 .toFormatter(); 956 } 957 return od; 958 } 959 960 968 public static DateTimeFormatter ordinalDateTime() { 969 if (odt == null) { 970 odt = new DateTimeFormatterBuilder() 971 .append(ordinalDate()) 972 .append(tTime()) 973 .toFormatter(); 974 } 975 return odt; 976 } 977 978 986 public static DateTimeFormatter ordinalDateTimeNoMillis() { 987 if (odtx == null) { 988 odtx = new DateTimeFormatterBuilder() 989 .append(ordinalDate()) 990 .append(tTimeNoMillis()) 991 .toFormatter(); 992 } 993 return odtx; 994 } 995 996 1002 public static DateTimeFormatter weekDate() { 1003 return weekyearWeekDay(); 1004 } 1005 1006 1013 public static DateTimeFormatter weekDateTime() { 1014 if (wdt == null) { 1015 wdt = new DateTimeFormatterBuilder() 1016 .append(weekDate()) 1017 .append(tTime()) 1018 .toFormatter(); 1019 } 1020 return wdt; 1021 } 1022 1023 1030 public static DateTimeFormatter weekDateTimeNoMillis() { 1031 if (wdtx == null) { 1032 wdtx = new DateTimeFormatterBuilder() 1033 .append(weekDate()) 1034 .append(tTimeNoMillis()) 1035 .toFormatter(); 1036 } 1037 return wdtx; 1038 } 1039 1040 1047 public static DateTimeFormatter basicDate() { 1048 if (bd == null) { 1049 bd = new DateTimeFormatterBuilder() 1050 .appendYear(4, 4) 1051 .appendMonthOfYear(2) 1052 .appendDayOfMonth(2) 1053 .toFormatter(); 1054 } 1055 return bd; 1056 } 1057 1058 1066 public static DateTimeFormatter basicTime() { 1067 if (bt == null) { 1068 bt = new DateTimeFormatterBuilder() 1069 .appendHourOfDay(2) 1070 .appendMinuteOfHour(2) 1071 .appendSecondOfMinute(2) 1072 .appendLiteral('.') 1073 .appendMillisOfSecond(3) 1074 .appendTimeZoneOffset("Z", false, 2, 2) 1075 .toFormatter(); 1076 } 1077 return bt; 1078 } 1079 1080 1087 public static DateTimeFormatter basicTimeNoMillis() { 1088 if (btx == null) { 1089 btx = new DateTimeFormatterBuilder() 1090 .appendHourOfDay(2) 1091 .appendMinuteOfHour(2) 1092 .appendSecondOfMinute(2) 1093 .appendTimeZoneOffset("Z", false, 2, 2) 1094 .toFormatter(); 1095 } 1096 return btx; 1097 } 1098 1099 1107 public static DateTimeFormatter basicTTime() { 1108 if (btt == null) { 1109 btt = new DateTimeFormatterBuilder() 1110 .append(literalTElement()) 1111 .append(basicTime()) 1112 .toFormatter(); 1113 } 1114 return btt; 1115 } 1116 1117 1125 public static DateTimeFormatter basicTTimeNoMillis() { 1126 if (bttx == null) { 1127 bttx = new DateTimeFormatterBuilder() 1128 .append(literalTElement()) 1129 .append(basicTimeNoMillis()) 1130 .toFormatter(); 1131 } 1132 return bttx; 1133 } 1134 1135 1142 public static DateTimeFormatter basicDateTime() { 1143 if (bdt == null) { 1144 bdt = new DateTimeFormatterBuilder() 1145 .append(basicDate()) 1146 .append(basicTTime()) 1147 .toFormatter(); 1148 } 1149 return bdt; 1150 } 1151 1152 1159 public static DateTimeFormatter basicDateTimeNoMillis() { 1160 if (bdtx == null) { 1161 bdtx = new DateTimeFormatterBuilder() 1162 .append(basicDate()) 1163 .append(basicTTimeNoMillis()) 1164 .toFormatter(); 1165 } 1166 return bdtx; 1167 } 1168 1169 1176 public static DateTimeFormatter basicOrdinalDate() { 1177 if (bod == null) { 1178 bod = new DateTimeFormatterBuilder() 1179 .appendYear(4, 4) 1180 .appendDayOfYear(3) 1181 .toFormatter(); 1182 } 1183 return bod; 1184 } 1185 1186 1194 public static DateTimeFormatter basicOrdinalDateTime() { 1195 if (bodt == null) { 1196 bodt = new DateTimeFormatterBuilder() 1197 .append(basicOrdinalDate()) 1198 .append(basicTTime()) 1199 .toFormatter(); 1200 } 1201 return bodt; 1202 } 1203 1204 1212 public static DateTimeFormatter basicOrdinalDateTimeNoMillis() { 1213 if (bodtx == null) { 1214 bodtx = new DateTimeFormatterBuilder() 1215 .append(basicOrdinalDate()) 1216 .append(basicTTimeNoMillis()) 1217 .toFormatter(); 1218 } 1219 return bodtx; 1220 } 1221 1222 1228 public static DateTimeFormatter basicWeekDate() { 1229 if (bwd == null) { 1230 bwd = new DateTimeFormatterBuilder() 1231 .appendWeekyear(4, 4) 1232 .appendLiteral('W') 1233 .appendWeekOfWeekyear(2) 1234 .appendDayOfWeek(1) 1235 .toFormatter(); 1236 } 1237 return bwd; 1238 } 1239 1240 1247 public static DateTimeFormatter basicWeekDateTime() { 1248 if (bwdt == null) { 1249 bwdt = new DateTimeFormatterBuilder() 1250 .append(basicWeekDate()) 1251 .append(basicTTime()) 1252 .toFormatter(); 1253 } 1254 return bwdt; 1255 } 1256 1257 1264 public static DateTimeFormatter basicWeekDateTimeNoMillis() { 1265 if (bwdtx == null) { 1266 bwdtx = new DateTimeFormatterBuilder() 1267 .append(basicWeekDate()) 1268 .append(basicTTimeNoMillis()) 1269 .toFormatter(); 1270 } 1271 return bwdtx; 1272 } 1273 1274 1280 public static DateTimeFormatter year() { 1281 return yearElement(); 1282 } 1283 1284 1290 public static DateTimeFormatter yearMonth() { 1291 if (ym == null) { 1292 ym = new DateTimeFormatterBuilder() 1293 .append(yearElement()) 1294 .append(monthElement()) 1295 .toFormatter(); 1296 } 1297 return ym; 1298 } 1299 1300 1306 public static DateTimeFormatter yearMonthDay() { 1307 if (ymd == null) { 1308 ymd = new DateTimeFormatterBuilder() 1309 .append(yearElement()) 1310 .append(monthElement()) 1311 .append(dayOfMonthElement()) 1312 .toFormatter(); 1313 } 1314 return ymd; 1315 } 1316 1317 1322 public static DateTimeFormatter weekyear() { 1323 return weekyearElement(); 1324 } 1325 1326 1332 public static DateTimeFormatter weekyearWeek() { 1333 if (ww == null) { 1334 ww = new DateTimeFormatterBuilder() 1335 .append(weekyearElement()) 1336 .append(weekElement()) 1337 .toFormatter(); 1338 } 1339 return ww; 1340 } 1341 1342 1348 public static DateTimeFormatter weekyearWeekDay() { 1349 if (wwd == null) { 1350 wwd = new DateTimeFormatterBuilder() 1351 .append(weekyearElement()) 1352 .append(weekElement()) 1353 .append(dayOfWeekElement()) 1354 .toFormatter(); 1355 } 1356 return wwd; 1357 } 1358 1359 1364 public static DateTimeFormatter hour() { 1365 return hourElement(); 1366 } 1367 1368 1374 public static DateTimeFormatter hourMinute() { 1375 if (hm == null) { 1376 hm = new DateTimeFormatterBuilder() 1377 .append(hourElement()) 1378 .append(minuteElement()) 1379 .toFormatter(); 1380 } 1381 return hm; 1382 } 1383 1384 1390 public static DateTimeFormatter hourMinuteSecond() { 1391 if (hms == null) { 1392 hms = new DateTimeFormatterBuilder() 1393 .append(hourElement()) 1394 .append(minuteElement()) 1395 .append(secondElement()) 1396 .toFormatter(); 1397 } 1398 return hms; 1399 } 1400 1401 1408 public static DateTimeFormatter hourMinuteSecondMillis() { 1409 if (hmsl == null) { 1410 hmsl = new DateTimeFormatterBuilder() 1411 .append(hourElement()) 1412 .append(minuteElement()) 1413 .append(secondElement()) 1414 .append(millisElement()) 1415 .toFormatter(); 1416 } 1417 return hmsl; 1418 } 1419 1420 1427 public static DateTimeFormatter hourMinuteSecondFraction() { 1428 if (hmsf == null) { 1429 hmsf = new DateTimeFormatterBuilder() 1430 .append(hourElement()) 1431 .append(minuteElement()) 1432 .append(secondElement()) 1433 .append(fractionElement()) 1434 .toFormatter(); 1435 } 1436 return hmsf; 1437 } 1438 1439 1445 public static DateTimeFormatter dateHour() { 1446 if (dh == null) { 1447 dh = new DateTimeFormatterBuilder() 1448 .append(date()) 1449 .append(literalTElement()) 1450 .append(hour()) 1451 .toFormatter(); 1452 } 1453 return dh; 1454 } 1455 1456 1462 public static DateTimeFormatter dateHourMinute() { 1463 if (dhm == null) { 1464 dhm = new DateTimeFormatterBuilder() 1465 .append(date()) 1466 .append(literalTElement()) 1467 .append(hourMinute()) 1468 .toFormatter(); 1469 } 1470 return dhm; 1471 } 1472 1473 1480 public static DateTimeFormatter dateHourMinuteSecond() { 1481 if (dhms == null) { 1482 dhms = new DateTimeFormatterBuilder() 1483 .append(date()) 1484 .append(literalTElement()) 1485 .append(hourMinuteSecond()) 1486 .toFormatter(); 1487 } 1488 return dhms; 1489 } 1490 1491 1498 public static DateTimeFormatter dateHourMinuteSecondMillis() { 1499 if (dhmsl == null) { 1500 dhmsl = new DateTimeFormatterBuilder() 1501 .append(date()) 1502 .append(literalTElement()) 1503 .append(hourMinuteSecondMillis()) 1504 .toFormatter(); 1505 } 1506 return dhmsl; 1507 } 1508 1509 1516 public static DateTimeFormatter dateHourMinuteSecondFraction() { 1517 if (dhmsf == null) { 1518 dhmsf = new DateTimeFormatterBuilder() 1519 .append(date()) 1520 .append(literalTElement()) 1521 .append(hourMinuteSecondFraction()) 1522 .toFormatter(); 1523 } 1524 return dhmsf; 1525 } 1526 1527 private static DateTimeFormatter yearElement() { 1529 if (ye == null) { 1530 ye = new DateTimeFormatterBuilder() 1531 .appendYear(4, 9) 1532 .toFormatter(); 1533 } 1534 return ye; 1535 } 1536 1537 private static DateTimeFormatter monthElement() { 1538 if (mye == null) { 1539 mye = new DateTimeFormatterBuilder() 1540 .appendLiteral('-') 1541 .appendMonthOfYear(2) 1542 .toFormatter(); 1543 } 1544 return mye; 1545 } 1546 1547 private static DateTimeFormatter dayOfMonthElement() { 1548 if (dme == null) { 1549 dme = new DateTimeFormatterBuilder() 1550 .appendLiteral('-') 1551 .appendDayOfMonth(2) 1552 .toFormatter(); 1553 } 1554 return dme; 1555 } 1556 1557 private static DateTimeFormatter weekyearElement() { 1558 if (we == null) { 1559 we = new DateTimeFormatterBuilder() 1560 .appendWeekyear(4, 9) 1561 .toFormatter(); 1562 } 1563 return we; 1564 } 1565 1566 private static DateTimeFormatter weekElement() { 1567 if (wwe == null) { 1568 wwe = new DateTimeFormatterBuilder() 1569 .appendLiteral("-W") 1570 .appendWeekOfWeekyear(2) 1571 .toFormatter(); 1572 } 1573 return wwe; 1574 } 1575 1576 private static DateTimeFormatter dayOfWeekElement() { 1577 if (dwe == null) { 1578 dwe = new DateTimeFormatterBuilder() 1579 .appendLiteral('-') 1580 .appendDayOfWeek(1) 1581 .toFormatter(); 1582 } 1583 return dwe; 1584 } 1585 1586 private static DateTimeFormatter dayOfYearElement() { 1587 if (dye == null) { 1588 dye = new DateTimeFormatterBuilder() 1589 .appendLiteral('-') 1590 .appendDayOfYear(3) 1591 .toFormatter(); 1592 } 1593 return dye; 1594 } 1595 1596 private static DateTimeFormatter literalTElement() { 1597 if (lte == null) { 1598 lte = new DateTimeFormatterBuilder() 1599 .appendLiteral('T') 1600 .toFormatter(); 1601 } 1602 return lte; 1603 } 1604 1605 private static DateTimeFormatter hourElement() { 1606 if (hde == null) { 1607 hde = new DateTimeFormatterBuilder() 1608 .appendHourOfDay(2) 1609 .toFormatter(); 1610 } 1611 return hde; 1612 } 1613 1614 private static DateTimeFormatter minuteElement() { 1615 if (mhe == null) { 1616 mhe = new DateTimeFormatterBuilder() 1617 .appendLiteral(':') 1618 .appendMinuteOfHour(2) 1619 .toFormatter(); 1620 } 1621 return mhe; 1622 } 1623 1624 private static DateTimeFormatter secondElement() { 1625 if (sme == null) { 1626 sme = new DateTimeFormatterBuilder() 1627 .appendLiteral(':') 1628 .appendSecondOfMinute(2) 1629 .toFormatter(); 1630 } 1631 return sme; 1632 } 1633 1634 private static DateTimeFormatter millisElement() { 1635 if (lse == null) { 1636 lse = new DateTimeFormatterBuilder() 1637 .appendLiteral('.') 1638 .appendMillisOfSecond(3) 1639 .toFormatter(); 1640 } 1641 return lse; 1642 } 1643 1644 private static DateTimeFormatter fractionElement() { 1645 if (fse == null) { 1646 fse = new DateTimeFormatterBuilder() 1647 .appendLiteral('.') 1648 .appendFractionOfSecond(3, 9) 1651 .toFormatter(); 1652 } 1653 return fse; 1654 } 1655 1656 private static DateTimeFormatter offsetElement() { 1657 if (ze == null) { 1658 ze = new DateTimeFormatterBuilder() 1659 .appendTimeZoneOffset("Z", true, 2, 4) 1660 .toFormatter(); 1661 } 1662 return ze; 1663 } 1664 1665} 1666 | Popular Tags |