java.lang.Object
org.refcodes.time.DateUtility
-
Method Summary
Modifier and TypeMethodDescriptionstatic Date
toDate
(String aDateString, DateTimeFormatter[] aDateTimeFormatters) static LocalDate
toLocalDate
(String aDateString, DateTimeFormatter[] aDateTimeFormatters) static LocalDateTime
toLocalDateTime
(String aDateString, DateTimeFormatter[] aDateTimeFormatters) Parses aString
to retrieve aLocalDateTime
from it, using the providedDateTimeFormatter
instances.
-
Method Details
-
toDate
Parses aString
to retrieve aDate
from it, using the providedDateTimeFormatter
instances. The first one being able to parse aDate
from theString
will be used and thatDate
is returned. If noneDateTimeFormatter
instances were able to parse the providedString
, then the first (as being provided in the array)DateTimeFormatter
's parse exception is thrown.- Parameters:
aDateString
- The dateString
to be parsed.aDateTimeFormatters
- TheDateTimeFormatter
instances to be tried out, starting with the first one.- Returns:
- A
Date
retrieved from the givenString
. - Throws:
DateTimeException
- Thrown in case none of the providedDateTimeFormatter
instances was able to parse the string. Then the first caughtDateTimeException
is thrown.
-
toLocalDate
Parses aString
to retrieve aLocalDate
from it, using the providedDateTimeFormatter
instances. The first one being able to parse aLocalDate
from theString
will be used and thatLocalDate
is returned. If noneDateTimeFormatter
instances were able to parse the providedString
, then the first (as being provided in the array)DateTimeFormatter
's parse exception is thrown.- Parameters:
aDateString
- The dateString
to be parsed.aDateTimeFormatters
- TheDateTimeFormatter
instances to be tried out, starting with the first one.- Returns:
- A
LocalDate
retrieved from the givenString
. - Throws:
DateTimeException
- Thrown in case none of the providedDateTimeFormatter
instances was able to parse the string. Then the first caughtDateTimeException
is thrown.
-
toLocalDateTime
public static LocalDateTime toLocalDateTime(String aDateString, DateTimeFormatter[] aDateTimeFormatters) Parses aString
to retrieve aLocalDateTime
from it, using the providedDateTimeFormatter
instances. The first one being able to parse aLocalDateTime
from theString
will be used and thatLocalDateTime
is returned. If noneDateTimeFormatter
instances were able to parse the providedString
, then the first (as being provided in the array)DateTimeFormatter
's parse exception is thrown.- Parameters:
aDateString
- The dateString
to be parsed.aDateTimeFormatters
- TheDateTimeFormatter
instances to be tried out, starting with the first one.- Returns:
- A
LocalDateTime
retrieved from the givenString
. - Throws:
DateTimeException
- Thrown in case none of the providedDateTimeFormatter
instances was able to parse the string. Then the first caughtDateTimeException
is thrown.
-