- java.lang.Object
-
- org.refcodes.time.DateUtility
-
public final class DateUtility extends Object
The Class DateUtility.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static DatetoDate(String aDateString, DateTimeFormatter[] aDateTimeFormatters)static LocalDatetoLocalDate(String aDateString, DateTimeFormatter[] aDateTimeFormatters)static LocalDateTimetoLocalDateTime(String aDateString, DateTimeFormatter[] aDateTimeFormatters)Parses aStringto retrieve aLocalDateTimefrom it, using the providedDateTimeFormatterinstances.
-
-
-
Method Detail
-
toDate
public static Date toDate(String aDateString, DateTimeFormatter[] aDateTimeFormatters) throws DateTimeException
Parses aStringto retrieve aDatefrom it, using the providedDateTimeFormatterinstances. The first one being able to parse aDatefrom theStringwill be used and thatDateis returned. If noneDateTimeFormatterinstances were able to parse the providedString, then the first (as being provided in the array)DateTimeFormatter's parse exception is thrown.- Parameters:
aDateString- The dateStringto be parsed.aDateTimeFormatters- TheDateTimeFormatterinstances to be tried out, starting with the first one.- Returns:
- A
Dateretrieved from the givenString. - Throws:
DateTimeException- Thrown in case none of the providedDateTimeFormatterinstances was able to parse the string. Then the first caughtDateTimeExceptionis thrown.
-
toLocalDate
public static LocalDate toLocalDate(String aDateString, DateTimeFormatter[] aDateTimeFormatters) throws DateTimeException
Parses aStringto retrieve aLocalDatefrom it, using the providedDateTimeFormatterinstances. The first one being able to parse aLocalDatefrom theStringwill be used and thatLocalDateis returned. If noneDateTimeFormatterinstances were able to parse the providedString, then the first (as being provided in the array)DateTimeFormatter's parse exception is thrown.- Parameters:
aDateString- The dateStringto be parsed.aDateTimeFormatters- TheDateTimeFormatterinstances to be tried out, starting with the first one.- Returns:
- A
LocalDateretrieved from the givenString. - Throws:
DateTimeException- Thrown in case none of the providedDateTimeFormatterinstances was able to parse the string. Then the first caughtDateTimeExceptionis thrown.
-
toLocalDateTime
public static LocalDateTime toLocalDateTime(String aDateString, DateTimeFormatter[] aDateTimeFormatters) throws DateTimeException
Parses aStringto retrieve aLocalDateTimefrom it, using the providedDateTimeFormatterinstances. The first one being able to parse aLocalDateTimefrom theStringwill be used and thatLocalDateTimeis returned. If noneDateTimeFormatterinstances were able to parse the providedString, then the first (as being provided in the array)DateTimeFormatter's parse exception is thrown.- Parameters:
aDateString- The dateStringto be parsed.aDateTimeFormatters- TheDateTimeFormatterinstances to be tried out, starting with the first one.- Returns:
- A
LocalDateTimeretrieved from the givenString. - Throws:
DateTimeException- Thrown in case none of the providedDateTimeFormatterinstances was able to parse the string. Then the first caughtDateTimeExceptionis thrown.
-
-