Java Utililty Methods LocalTime

List of utility methods to do LocalTime

Description

The list of methods to do LocalTime are organized into topic(s).

Method

DateasDate(LocalTime localTime)
Obtains an instance of Date from a local time object.
return asDate(localTime, getDefaultTimeZone());
StringconvertLocalTimeToString(LocalTime time)
convert Local Time To String
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern(TIME_FORMAT);
return time.format(dateTimeFormatter);
booleancurrentTimeIsBetween(LocalTime from, LocalTime to)
Check if current time is between given local times
LocalTime current = LocalTime.now();
if (from == null || to == null)
    return true;
return (current.isAfter(from) && current.isBefore(to)) || current.equals(from) || current.equals(to);
LocalTimedeserializeLocalTime(String date)
deserialize Local Time
return LocalTime.parse(date, ISO_LOCAL_TIME_FORMAT);
char[]fastTimeWrite(LocalTime localTime)
fast Time Write
char[] c = new char[5];
int h = localTime.getHour();
c[0] = (char) ('0' + (h / 10));
c[1] = (char) ('0' + (h % 10));
c[2] = (char) (':');
int m = localTime.getMinute();
c[3] = (char) ('0' + (m / 10));
c[4] = (char) ('0' + (m % 10));
...
LocalTimegetTimeDiff(LocalTime start, LocalTime end)
This will return the time difference between a starting and ending time
return null;
booleanisBetween(LocalTime lt, LocalTime startTime, LocalTime endTime)
is Between
return lt.compareTo(startTime) >= 0 && lt.compareTo(endTime) <= 0;
booleanisLocalTimeInRange(LocalTime value, LocalTime optionalMinimum, LocalTime optionalMaximum, boolean inclusiveOfEndpoints)
isLocalTimeInRange, This returns true if the specified value is inside of the specified range.
LocalTime minimum = (optionalMinimum == null) ? LocalTime.MIN : optionalMinimum;
LocalTime maximum = (optionalMaximum == null) ? LocalTime.MAX : optionalMaximum;
if (value == null) {
    return false;
if (maximum.isBefore(minimum) || maximum.equals(minimum)) {
    return false;
if (inclusiveOfEndpoints) {
    return ((value.isAfter(minimum) || value.equals(minimum))
            && (value.isBefore(maximum) || value.equals(maximum)));
} else {
    return (value.isAfter(minimum) && value.isBefore(maximum));
LocalTimeparseLocalTime(String string)
This function attempts to parse a time.
return LocalTime.parse(string, POTENTIAL_FORMATS);
voidrepDiff(LocalTime start, LocalTime end, byte type)
Reports the difference between two LocalTimes reports total difference in one unit of time
switch (type) {
case 0:
    break;
case 1:
    long diff = Duration.between(start, end).get(ChronoUnit.MINUTES);
    break;
case 2:
    break;
...