@@ -52,7 +52,7 @@ public class DateUtil {
52
52
* @return a {@code yyyy-MM-dd} {@link DateFormat}
53
53
*/
54
54
public static DateFormat newIsoDateFormat () {
55
- return strictDateFormatForPattern ( "yyyy-MM-dd" );
55
+ return newIsoDateFormat ( false );
56
56
}
57
57
58
58
/**
@@ -61,15 +61,15 @@ public static DateFormat newIsoDateFormat() {
61
61
* @return a {@code yyyy-MM-dd'T'HH:mm:ssX} {@link DateFormat}
62
62
*/
63
63
public static DateFormat newIsoDateTimeWithIsoTimeZoneFormat () {
64
- return strictDateFormatForPattern ( "yyyy-MM-dd'T'HH:mm:ssX" );
64
+ return newIsoDateTimeWithIsoTimeZoneFormat ( false );
65
65
}
66
66
67
67
/**
68
68
* ISO 8601 date-time format (yyyy-MM-dd'T'HH:mm:ss), example : <code>2003-04-26T13:01:02</code>
69
69
* @return a {@code yyyy-MM-dd'T'HH:mm:ss} {@link DateFormat}
70
70
*/
71
71
public static DateFormat newIsoDateTimeFormat () {
72
- return strictDateFormatForPattern ( "yyyy-MM-dd'T'HH:mm:ss" );
72
+ return newIsoDateTimeFormat ( false );
73
73
}
74
74
75
75
/**
@@ -78,7 +78,7 @@ public static DateFormat newIsoDateTimeFormat() {
78
78
* @return a {@code yyyy-MM-dd'T'HH:mm:ss.SSS} {@link DateFormat}
79
79
*/
80
80
public static DateFormat newIsoDateTimeWithMsFormat () {
81
- return strictDateFormatForPattern ( "yyyy-MM-dd'T'HH:mm:ss.SSS" );
81
+ return newIsoDateTimeWithMsFormat ( false );
82
82
}
83
83
84
84
/**
@@ -87,7 +87,7 @@ public static DateFormat newIsoDateTimeWithMsFormat() {
87
87
* @return a {@code yyyy-MM-dd'T'HH:mm:ss.SSSX} {@link DateFormat}
88
88
*/
89
89
public static DateFormat newIsoDateTimeWithMsAndIsoTimeZoneFormat () {
90
- return strictDateFormatForPattern ( "yyyy-MM-dd'T'HH:mm:ss.SSSX" );
90
+ return newIsoDateTimeWithMsAndIsoTimeZoneFormat ( false );
91
91
}
92
92
93
93
/**
@@ -96,12 +96,70 @@ public static DateFormat newIsoDateTimeWithMsAndIsoTimeZoneFormat() {
96
96
* @return a {@code yyyy-MM-dd HH:mm:ss.SSS} {@link DateFormat}
97
97
*/
98
98
public static DateFormat newTimestampDateFormat () {
99
- return strictDateFormatForPattern ( "yyyy-MM-dd HH:mm:ss.SSS" );
99
+ return newTimestampDateFormat ( false );
100
100
}
101
101
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 ) {
103
161
DateFormat dateFormat = new SimpleDateFormat (pattern );
104
- dateFormat .setLenient (false );
162
+ dateFormat .setLenient (lenient );
105
163
return dateFormat ;
106
164
}
107
165
0 commit comments