Class DateTimes
public class DateTimes extends Object
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classDateTimes.Interval -
Constructor Summary
Constructors Constructor Description DateTimes() -
Method Summary
Modifier and Type Method Description static LocalDateTimeparseDateTime(@NonNull String dateTime)The network law dictates: Be liberal in what you accept, be conservative in what you emit.static LocalDateTimeparseDateTime(@NonNull String dateTime, int numberOfComponents)Like DateTimeUtilparseDateTime(String), but accepts an additional argument which specifies how many components of the timestamp will be taken into account.InstantparseInstant(String string)DateTimes.IntervalparseInterval(String string)DateTimes.IntervalparseInterval(String begin, String end)LocalDatetoLocalDate(Instant instant)LocalTimetoLocalTime(Instant instant)
-
Constructor Details
-
DateTimes
public DateTimes()
-
-
Method Details
-
parseInterval
-
parseInterval
-
parseInstant
- Throws:
IllegalArgumentException
-
toLocalDate
-
toLocalTime
-
parseDateTime
@Nonnull public static LocalDateTime parseDateTime(@NonNull @NonNull String dateTime) throws IllegalArgumentExceptionThe network law dictates: Be liberal in what you accept, be conservative in what you emit.The law of personal consistency prefers to voice your opinion, harshly, but friendly.
This function will accept timestamps formatted in a variety of formats, and ignores everything it does not understand. It will explode the given string and reduce it to groups of decimal digits. If any of these groups themselves look like a timestamp such as 20191231 it will attempt to make sense out of that. Otherwise it assumes from left to right year, month, day-of-month, hour, minute, second. If any of these components are missing (from right to left) it will default them to zero.
That way this function accepts timestamps such as:
201201012012-01-01-23595920120101.2359592012-05-30T23:59:592012-05-30 23:59:592012-05-30-23-59-59
- Parameters:
dateTime- A timestamp given as a string.- Returns:
- A local date time.
- Throws:
IllegalArgumentException
-
parseDateTime
@Nonnull public static LocalDateTime parseDateTime(@NonNull @NonNull String dateTime, int numberOfComponents) throws IllegalArgumentExceptionLike DateTimeUtilparseDateTime(String), but accepts an additional argument which specifies how many components of the timestamp will be taken into account.For instance an invocation with numberOfComponents=4 will ignore minute and second information, if at all provided.
- Parameters:
dateTime- A timestamp given as a string.numberOfComponents- How many components to take into account.- Returns:
- A local date time.
- Throws:
IllegalArgumentException
-