@@ -52,7 +52,7 @@ public class DateUtil {
5252 * @return a {@code yyyy-MM-dd} {@link DateFormat}
5353 */
5454 public static DateFormat newIsoDateFormat () {
55- return strictDateFormatForPattern ( "yyyy-MM-dd" );
55+ return newIsoDateFormat ( false );
5656 }
5757
5858 /**
@@ -61,15 +61,15 @@ public static DateFormat newIsoDateFormat() {
6161 * @return a {@code yyyy-MM-dd'T'HH:mm:ssX} {@link DateFormat}
6262 */
6363 public static DateFormat newIsoDateTimeWithIsoTimeZoneFormat () {
64- return strictDateFormatForPattern ( "yyyy-MM-dd'T'HH:mm:ssX" );
64+ return newIsoDateTimeWithIsoTimeZoneFormat ( false );
6565 }
6666
6767 /**
6868 * ISO 8601 date-time format (yyyy-MM-dd'T'HH:mm:ss), example : <code>2003-04-26T13:01:02</code>
6969 * @return a {@code yyyy-MM-dd'T'HH:mm:ss} {@link DateFormat}
7070 */
7171 public static DateFormat newIsoDateTimeFormat () {
72- return strictDateFormatForPattern ( "yyyy-MM-dd'T'HH:mm:ss" );
72+ return newIsoDateTimeFormat ( false );
7373 }
7474
7575 /**
@@ -78,7 +78,7 @@ public static DateFormat newIsoDateTimeFormat() {
7878 * @return a {@code yyyy-MM-dd'T'HH:mm:ss.SSS} {@link DateFormat}
7979 */
8080 public static DateFormat newIsoDateTimeWithMsFormat () {
81- return strictDateFormatForPattern ( "yyyy-MM-dd'T'HH:mm:ss.SSS" );
81+ return newIsoDateTimeWithMsFormat ( false );
8282 }
8383
8484 /**
@@ -87,7 +87,7 @@ public static DateFormat newIsoDateTimeWithMsFormat() {
8787 * @return a {@code yyyy-MM-dd'T'HH:mm:ss.SSSX} {@link DateFormat}
8888 */
8989 public static DateFormat newIsoDateTimeWithMsAndIsoTimeZoneFormat () {
90- return strictDateFormatForPattern ( "yyyy-MM-dd'T'HH:mm:ss.SSSX" );
90+ return newIsoDateTimeWithMsAndIsoTimeZoneFormat ( false );
9191 }
9292
9393 /**
@@ -96,12 +96,70 @@ public static DateFormat newIsoDateTimeWithMsAndIsoTimeZoneFormat() {
9696 * @return a {@code yyyy-MM-dd HH:mm:ss.SSS} {@link DateFormat}
9797 */
9898 public static DateFormat newTimestampDateFormat () {
99- return strictDateFormatForPattern ( "yyyy-MM-dd HH:mm:ss.SSS" );
99+ return newTimestampDateFormat ( false );
100100 }
101101
102- private static DateFormat strictDateFormatForPattern (String pattern ) {
102+ /**
103+ * ISO 8601 date format (yyyy-MM-dd), example : <code>2003-04-23</code>
104+ * @param lenientParsing whether or not parsing the date is lenient
105+ * @return a {@code yyyy-MM-dd} {@link DateFormat}
106+ */
107+ public static DateFormat newIsoDateFormat (boolean lenientParsing ) {
108+ return dateFormatForPattern ("yyyy-MM-dd" , lenientParsing );
109+ }
110+
111+ /**
112+ * ISO 8601 date-time format with ISO time zone (yyyy-MM-dd'T'HH:mm:ssX), example :
113+ * <code>2003-04-26T03:01:02+00:00</code>
114+ * @param lenientParsing whether or not parsing the date is lenient
115+ * @return a {@code yyyy-MM-dd'T'HH:mm:ssX} {@link DateFormat}
116+ */
117+ public static DateFormat newIsoDateTimeWithIsoTimeZoneFormat (boolean lenientParsing ) {
118+ return dateFormatForPattern ("yyyy-MM-dd'T'HH:mm:ssX" , lenientParsing );
119+ }
120+
121+ /**
122+ * ISO 8601 date-time format (yyyy-MM-dd'T'HH:mm:ss), example : <code>2003-04-26T13:01:02</code>
123+ * @param lenientParsing whether or not parsing the date is lenient
124+ * @return a {@code yyyy-MM-dd'T'HH:mm:ss} {@link DateFormat}
125+ */
126+ public static DateFormat newIsoDateTimeFormat (boolean lenientParsing ) {
127+ return dateFormatForPattern ("yyyy-MM-dd'T'HH:mm:ss" , lenientParsing );
128+ }
129+
130+ /**
131+ * ISO 8601 date-time format with millisecond (yyyy-MM-dd'T'HH:mm:ss.SSS), example :
132+ * <code>2003-04-26T03:01:02.999</code>
133+ * @param lenientParsing whether or not parsing the date is lenient
134+ * @return a {@code yyyy-MM-dd'T'HH:mm:ss.SSS} {@link DateFormat}
135+ */
136+ public static DateFormat newIsoDateTimeWithMsFormat (boolean lenientParsing ) {
137+ return dateFormatForPattern ("yyyy-MM-dd'T'HH:mm:ss.SSS" , lenientParsing );
138+ }
139+
140+ /**
141+ * ISO 8601 date-time format with millisecond and ISO time zone (yyyy-MM-dd'T'HH:mm:ss.SSSX), example :
142+ * <code>2003-04-26T03:01:02.758+00:00</code>
143+ * @param lenientParsing whether or not parsing the date is lenient
144+ * @return a {@code yyyy-MM-dd'T'HH:mm:ss.SSSX} {@link DateFormat}
145+ */
146+ public static DateFormat newIsoDateTimeWithMsAndIsoTimeZoneFormat (boolean lenientParsing ) {
147+ return dateFormatForPattern ("yyyy-MM-dd'T'HH:mm:ss.SSSX" , lenientParsing );
148+ }
149+
150+ /**
151+ * {@link java.sql.Timestamp} date-time format with millisecond (yyyy-MM-dd HH:mm:ss.SSS), example :
152+ * <code>2003-04-26 03:01:02.999</code>
153+ * @param lenientParsing whether or not parsing the date is lenient
154+ * @return a {@code yyyy-MM-dd HH:mm:ss.SSS} {@link DateFormat}
155+ */
156+ public static DateFormat newTimestampDateFormat (boolean lenientParsing ) {
157+ return dateFormatForPattern ("yyyy-MM-dd HH:mm:ss.SSS" , lenientParsing );
158+ }
159+
160+ private static DateFormat dateFormatForPattern (String pattern , boolean lenient ) {
103161 DateFormat dateFormat = new SimpleDateFormat (pattern );
104- dateFormat .setLenient (false );
162+ dateFormat .setLenient (lenient );
105163 return dateFormat ;
106164 }
107165
0 commit comments