本文整理了Java中java.time.LocalTime.isBefore()
方法的一些代码示例,展示了LocalTime.isBefore()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。LocalTime.isBefore()
方法的具体详情如下:
包路径:java.time.LocalTime
类名称:LocalTime
方法名:isBefore
[英]Checks if this LocalTime is before the specified time.
The comparison is based on the time-line position of the time within a day.
[中]检查此LocalTime是否早于指定的时间。
比较基于一天内时间的时间线位置。
代码示例来源:origin: yu199195/Raincat
/**
* 判断时间是否在指定的时间段之类.
*
* @param date 需要判断的时间
* @param start 时间段的起始时间
* @param end 时间段的截止时间
* @return true or false
*/
public static boolean isBetween(final LocalTime date, final LocalTime start, final LocalTime end) {
if (date == null || start == null || end == null) {
throw new IllegalArgumentException("日期不能为空");
}
return date.isAfter(start) && date.isBefore(end);
}
代码示例来源:origin: oracle/helidon
boolean isValid(LocalTime nowTime) {
return from.isBefore(nowTime) && to.isAfter(nowTime);
}
代码示例来源:origin: Alluxio/alluxio
/**
* Primitive that is invoked periodically for cleaning the registry from clients that has become
* stale.
*/
private void cleanupStaleClients() {
LocalTime cleanupTime = LocalTime.now();
LOG.debug("Starting cleanup authentication registry at {}", cleanupTime);
// Get a list of stale clients under read lock.
List<UUID> staleChannels = new ArrayList<>();
for (Map.Entry<UUID, AuthenticatedChannelInfo> clientEntry : mChannels.entrySet()) {
LocalTime lat = clientEntry.getValue().getLastAccessTime();
if (lat.plusSeconds(mCleanupIntervalMs / 1000).isBefore(cleanupTime)) {
staleChannels.add(clientEntry.getKey());
}
}
// Unregister stale clients.
LOG.debug("Found {} stale channels for cleanup.", staleChannels.size());
for (UUID clientId : staleChannels) {
unregisterChannel(clientId);
}
LOG.debug("Finished state channel cleanup at {}", LocalTime.now());
}
代码示例来源:origin: kiegroup/optaplanner
.filter(timeslot -> timeslot.getStartDateTime().toLocalTime().isBefore(LocalTime.of(12,0)))
.collect(Collectors.toCollection(LinkedHashSet::new));
} else if (segmentRandom < 0.50) {
.filter(timeslot -> !timeslot.getStartDateTime().toLocalTime().isBefore(LocalTime.of(12,0)))
.collect(Collectors.toCollection(LinkedHashSet::new));
} else if (segmentRandom < 0.75) {
代码示例来源:origin: org.assertj/assertj-core
/**
* Verifies that the actual {@code LocalTime} is <b>strictly</b> before the given one.
* <p>
* Example :
* <pre><code class='java'> assertThat(parse("12:00:00")).isBefore(parse("13:00:00"));</code></pre>
*
* @param other the given {@link LocalTime}.
* @return this assertion object.
* @throws AssertionError if the actual {@code LocalTime} is {@code null}.
* @throws IllegalArgumentException if other {@code LocalTime} is {@code null}.
* @throws AssertionError if the actual {@code LocalTime} is not strictly before the given one.
*/
public SELF isBefore(LocalTime other) {
Objects.instance().assertNotNull(info, actual);
assertLocalTimeParameterIsNotNull(other);
if (!actual.isBefore(other)) {
throw Failures.instance().failure(info, shouldBeBefore(actual, other));
}
return myself;
}
代码示例来源:origin: org.assertj/assertj-core
/**
* Verifies that the actual {@code LocalTime} is after or equals to the given one.
* <p>
* Example :
* <pre><code class='java'> assertThat(parse("13:00:00")).isAfterOrEqualTo(parse("13:00:00"))
* .isAfterOrEqualTo(parse("12:00:00"));</code></pre>
*
* @param other the given {@link LocalTime}.
* @return this assertion object.
* @throws AssertionError if the actual {@code LocalTime} is {@code null}.
* @throws IllegalArgumentException if other {@code LocalTime} is {@code null}.
* @throws AssertionError if the actual {@code LocalTime} is not after or equals to the given one.
*/
public SELF isAfterOrEqualTo(LocalTime other) {
Objects.instance().assertNotNull(info, actual);
assertLocalTimeParameterIsNotNull(other);
if (actual.isBefore(other)) {
throw Failures.instance().failure(info, shouldBeAfterOrEqualsTo(actual, other));
}
return myself;
}
代码示例来源:origin: joel-costigliola/assertj-core
/**
* Verifies that the actual {@code LocalTime} is <b>strictly</b> before the given one.
* <p>
* Example :
* <pre><code class='java'> assertThat(parse("12:00:00")).isBefore(parse("13:00:00"));</code></pre>
*
* @param other the given {@link LocalTime}.
* @return this assertion object.
* @throws AssertionError if the actual {@code LocalTime} is {@code null}.
* @throws IllegalArgumentException if other {@code LocalTime} is {@code null}.
* @throws AssertionError if the actual {@code LocalTime} is not strictly before the given one.
*/
public SELF isBefore(LocalTime other) {
Objects.instance().assertNotNull(info, actual);
assertLocalTimeParameterIsNotNull(other);
if (!actual.isBefore(other)) {
throw Failures.instance().failure(info, shouldBeBefore(actual, other));
}
return myself;
}
代码示例来源:origin: joel-costigliola/assertj-core
/**
* Verifies that the actual {@code LocalTime} is after or equals to the given one.
* <p>
* Example :
* <pre><code class='java'> assertThat(parse("13:00:00")).isAfterOrEqualTo(parse("13:00:00"))
* .isAfterOrEqualTo(parse("12:00:00"));</code></pre>
*
* @param other the given {@link LocalTime}.
* @return this assertion object.
* @throws AssertionError if the actual {@code LocalTime} is {@code null}.
* @throws IllegalArgumentException if other {@code LocalTime} is {@code null}.
* @throws AssertionError if the actual {@code LocalTime} is not after or equals to the given one.
*/
public SELF isAfterOrEqualTo(LocalTime other) {
Objects.instance().assertNotNull(info, actual);
assertLocalTimeParameterIsNotNull(other);
if (actual.isBefore(other)) {
throw Failures.instance().failure(info, shouldBeAfterOrEqualsTo(actual, other));
}
return myself;
}
代码示例来源:origin: jtablesaw/tablesaw
if (row.getTime("End").isBefore(row.getTime("Start"))) {
end.get(row.getRowNumber()).plusDays(1);
if (row.getTime("End").isBefore(row.getTime("Start"))) {
end.get(row.getRowNumber()).plusDays(1);
代码示例来源:origin: stackoverflow.com
LocalTime now = LocalTime.now( ZoneId.of( "America/Montreal" ) );
Boolean isOpenNow =
( ! now.isBefore( LocalTime.of( 7 , 30 ) ) )
&&
now.isBefore( LocalTime.of( 23 , 00 ) )
;
代码示例来源:origin: stackoverflow.com
@Test()
public void testJoda() throws DGConstraintViolatedException {
DateTimeFormatter simpleTimeFormatter = DateTimeFormat.forPattern("HHmm");
LocalTime t1 = LocalTime.parse("0000", simpleTimeFormatter);
LocalTime t2 = LocalTime.MIDNIGHT;
Assert.assertTrue(t1.isBefore(t2));
}
代码示例来源:origin: stackoverflow.com
LocalTime openingTime = LocalTime.parse ( "04:00" );
LocalTime closingTime = LocalTime.parse ( "00:00" );
Boolean inRange = null;
LocalTime target = LocalTime.MIDNIGHT; // LocalTime.of ( 3 , 0) or LocalTime.of ( 4 , 0) or LocalTime.of ( 5 , 0) or LocalTime.now ( ZoneId.of ( "America/Los_Angeles" ) );
if ( closingTime.equals ( LocalTime.MIDNIGHT ) ) {
inRange = ( ! target.isBefore ( openingTime ) );
} else {
inRange = ( ( ! target.isBefore ( openingTime ) ) && ( target.isBefore ( closingTime ) ) );
}
代码示例来源:origin: com.netflix.spinnaker.orca/orca-core
int indexOf(LocalTime current) {
if (current.isBefore(this.start)) {
return -1;
} else if ((current.isAfter(this.start) || current.equals(this.start)) && (current.isBefore(this.end) || current.equals(this.end))) {
return 0;
} else {
return 1;
}
}
代码示例来源:origin: stackoverflow.com
public static boolean isOpen(LocalTime start, LocalTime end, LocalTime time) {
if (start.isAfter(end)) {
return !time.isBefore(start) || !time.isAfter(end);
} else {
return !time.isBefore(start) && !time.isAfter(end);
}
}
代码示例来源:origin: stackoverflow.com
public static void main(String[] args) {
LocalTime time = LocalTime.parse("11:22");
System.out.println(isBetween(time, LocalTime.of(10, 0), LocalTime.of(18, 0)));
}
public static boolean isBetween(LocalTime candidate, LocalTime start, LocalTime end) {
return !candidate.isBefore(start) && !candidate.isAfter(end); // Inclusive.
}
代码示例来源:origin: io.rhiot/rhiot-cloudplatform-service-device
@Override
public List<String> disconnected() {
return list().stream().filter(device -> {
LocalTime updated = ofInstant(ofEpochMilli(device.getLastUpdate().getTime()), ZoneId.systemDefault()).toLocalTime();
return updated.plus(disconnectionPeriod, ChronoUnit.MILLIS).isBefore(LocalTime.now());
}).map(Device::getDeviceId).collect(toList());
}
代码示例来源:origin: stackoverflow.com
LocalTime lowerBound = new LocalTime(10, 0);
LocalTime upperBound = new LocalTime(12, 30);
List<DateTime> filtered = new ArrayList<>();
for (DateTime dateTime : originals) {
LocalTime localTime = new LocalTime(dateTime);
if (lowerBound.isBefore(localTime) && upperBound.isAfter(localTime)) {
filtered.add(dateTime);
}
}
代码示例来源:origin: stackoverflow.com
LocalDateTime from = LocalDateTime.parse("2015-07-24T09:39:14.000Z", DateTimeFormatter.ISO_DATE_TIME);
LocalDateTime to = LocalDateTime.parse("2015-07-24T09:45:44.000Z", DateTimeFormatter.ISO_DATE_TIME);
System.out.println(from + " - " + to);
LocalTime fromTime = from.toLocalTime();
LocalTime toTime = to.toLocalTime();
System.out.println(fromTime + " - " + toTime);
System.out.println(fromTime + " before " + toTime + " = " + fromTime.isBefore(toTime));
System.out.println(fromTime + " after " + toTime + " = " + fromTime.isAfter(toTime));
System.out.println(fromTime + " equals " + toTime + " = " + fromTime.equals(toTime));
System.out.println(fromTime + " compareTo " + toTime + " = " + fromTime.compareTo(toTime));
代码示例来源:origin: nurkiewicz/rxjava-book-examples
private boolean isBusinessHour() {
ZoneId zone = ZoneId.of("Europe/Warsaw");
ZonedDateTime zdt = ZonedDateTime.now(zone);
LocalTime localTime = zdt.toLocalTime();
return !localTime.isBefore(BUSINESS_START)
&& !localTime.isAfter(BUSINESS_END);
}
代码示例来源:origin: stackoverflow.com
import java.time.Clock;
import java.time.LocalTime;
public class TimeMachine {
private LocalTime from = LocalTime.MIDNIGHT;
private LocalTime until = LocalTime.of(6, 0);
private Clock clock = Clock.systemDefaultZone();
public boolean isInInterval() {
LocalTime now = LocalTime.now(clock);
return now.isAfter(from) && now.isBefore(until);
}
}
内容来源于网络,如有侵权,请联系作者删除!