本文整理了Java中java.time.LocalDateTime.minusHours()
方法的一些代码示例,展示了LocalDateTime.minusHours()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。LocalDateTime.minusHours()
方法的具体详情如下:
包路径:java.time.LocalDateTime
类名称:LocalDateTime
方法名:minusHours
[英]Returns a copy of this LocalDateTime with the specified period in hours subtracted.
This instance is immutable and unaffected by this method call.
[中]返回此LocalDateTime的副本,并减去指定的时间段(以小时为单位)。
此实例是不可变的,不受此方法调用的影响。
代码示例来源:origin: apache/ignite
/** */
@Test
public void testPassTableWithTimeStampKeyCreation() {
final String creationQry = "CREATE TABLE %s (id TIMESTAMP primary key, dateField TIMESTAMP) " +
"WITH \"cache_name=%s, WRAP_VALUE=false\"";
Map<Timestamp, Timestamp> ent = new HashMap<>();
ent.put(Timestamp.valueOf(LocalDateTime.now()), Timestamp.valueOf(LocalDateTime.now().minusHours(1)));
ent.put(Timestamp.valueOf(LocalDateTime.now().minusHours(2)),
Timestamp.valueOf(LocalDateTime.now().minusHours(3)));
checkInsertUpdateDelete(creationQry, "Tab3", ent);
}
代码示例来源:origin: apache/geode
@Test
public void testAcceptFileWithCreateTimeNotAvailale() {
Path path = mock(Path.class);
when(path.toFile()).thenReturn(mock(File.class));
when(path.toFile().lastModified()).thenReturn(System.currentTimeMillis());
when(path.getFileSystem()).thenThrow(SecurityException.class);
// a filter with no start/end date should accept this file
LogFilter filter = new LogFilter(Level.INFO, null, null);
assertThat(filter.acceptsFile(path)).isTrue();
// a filter with a start date of now should not accept the file
filter = new LogFilter(Level.INFO, LocalDateTime.now(), null);
assertThat(filter.acceptsFile(path)).isFalse();
// a filter with a start date of now minus an hour should not accept the file
filter = new LogFilter(Level.INFO, LocalDateTime.now().minusHours(1), null);
assertThat(filter.acceptsFile(path)).isTrue();
// a filter with an end date of now should accept the file
filter = new LogFilter(Level.INFO, null, LocalDateTime.now());
assertThat(filter.acceptsFile(path)).isTrue();
// a filter with an end date of an hour ago should also accept the file, because we only
// know the last modified time of the file, when don't know what time this file is created, it
// may still be created more than an hour ago.
filter = new LogFilter(Level.INFO, null, LocalDateTime.now().minusHours(1));
assertThat(filter.acceptsFile(path)).isTrue();
}
代码示例来源:origin: apache/geode
filter = new LogFilter(Level.INFO, LocalDateTime.now().minusHours(1), null);
assertThat(filter.acceptsFile(path)).isTrue();
filter = new LogFilter(Level.INFO, null, LocalDateTime.now().minusHours(1));
assertThat(filter.acceptsFile(path)).isTrue();
代码示例来源:origin: Netflix/Priam
@Test
public void testRestoreStatus() throws Exception {
InstanceState.RestoreStatus restoreStatus = new InstanceState.RestoreStatus();
restoreStatus.setStartDateRange(LocalDateTime.now().minusDays(2).withSecond(0).withNano(0));
restoreStatus.setEndDateRange(LocalDateTime.now().minusHours(3).withSecond(0).withNano(0));
restoreStatus.setExecutionStartTime(LocalDateTime.now().withSecond(0).withNano(0));
LOG.info(restoreStatus.toString());
InstanceState.RestoreStatus restoreStatus1 =
GsonJsonSerializer.getGson()
.fromJson(restoreStatus.toString(), InstanceState.RestoreStatus.class);
LOG.info(restoreStatus1.toString());
Assert.assertEquals(
restoreStatus.getExecutionStartTime(), restoreStatus1.getExecutionStartTime());
Assert.assertEquals(restoreStatus.getStartDateRange(), restoreStatus1.getStartDateRange());
Assert.assertEquals(restoreStatus.getEndDateRange(), restoreStatus1.getEndDateRange());
}
}
代码示例来源:origin: JoleneOL/market-manage
/**
* 获取当前时间相对于清算时间的日期
* 比如清算时间是9点,现在是8点,那么当前时间相对于清算时间要减1天
*
* @return
*/
private LocalDate getOffsetDate() {
return LocalDateTime.now().minusHours(getOffsetHour()).toLocalDate();
}
代码示例来源:origin: stackoverflow.com
LocalDateTime dt1 = LocalDateTime.ofInstant(Instant.ofEpochMilli(1429174464829L), ZoneId.systemDefault());
LocalDateTime dt2 = LocalDateTime.now().plusDays(1);
System.out.println(dt1);
System.out.println(dt2);
StringJoiner sj = new StringJoiner(":");
long hours = ChronoUnit.HOURS.between(dt1, dt2);
sj.add(Long.toString(hours));
dt2 = dt2.minusHours(hours);
long mins = ChronoUnit.MINUTES.between(dt1, dt2);
sj.add(Long.toString(mins));
dt2 = dt2.minusMinutes(mins);
long secs = ChronoUnit.SECONDS.between(dt1, dt2);
sj.add(Long.toString(secs));
System.out.println(sj);
代码示例来源:origin: qala-io/datagen
public static LocalDateTime hourAgo() {
return now().minusHours(1);
}
public static LocalDateTime secondAgo() {
代码示例来源:origin: org.ojbc.bundles.intermediaries/subscription-notification-service-intermediary-common
@Override
public boolean hasNotificationBeenSent() {
boolean hasNotificationBeenSent = false;
if (lastNotificationSentTimestamp == null)
{
return false;
}
LocalDateTime now = LocalDateTime.now();
if (lastNotificationSentTimestamp.isAfter(now.minusHours(maxHoursBetweenNotifications)))
{
hasNotificationBeenSent = true;
}
return hasNotificationBeenSent;
}
代码示例来源:origin: allegro/hermes
private boolean isNotStale(Message message) {
return LocalDateTime.ofInstant(Instant.ofEpochMilli(message.getTimestamp()), ZoneId.systemDefault())
.isAfter(LocalDateTime.now().minusHours(messageMaxAgeHours));
}
代码示例来源:origin: com.scireum/sirius-db
/**
* Creates a date range filtering on the last hour.
*
* @return a date range for the given interval
*/
public static DateRange lastHour() {
return new DateRange("1h", NLS.get("DateRange.1h"), LocalDateTime.now().minusHours(1), LocalDateTime.now());
}
代码示例来源:origin: com.scireum/sirius-db
/**
* Creates a date range filtering on the last two hours.
*
* @return a date range for the given interval
*/
public static DateRange lastTwoHours() {
return new DateRange("2h", NLS.get("DateRange.2h"), LocalDateTime.now().minusHours(2), LocalDateTime.now());
}
代码示例来源:origin: com.scireum/sirius-search
/**
* Creates a date range filtering on the last two hours.
*
* @return a date range to be used in {@link Query#addDateRangeFacet(String, String, DateRange...)}
*/
public static DateRange lastTwoHours() {
return new DateRange("2h", NLS.get("DateRange.2h"), LocalDateTime.now().minusHours(2), LocalDateTime.now());
}
代码示例来源:origin: com.scireum/sirius-search
/**
* Creates a date range filtering on the last hour.
*
* @return a date range to be used in {@link Query#addDateRangeFacet(String, String, DateRange...)}
*/
public static DateRange lastHour() {
return new DateRange("1h", NLS.get("DateRange.1h"), LocalDateTime.now().minusHours(1), LocalDateTime.now());
}
代码示例来源:origin: nl.psek.fitnesse/psek-fitnesse-fixtures-general
/**
* Returns the supplied date time a number of hours in the specified output format.
*
* @param numberOfHours the number of hours in the past based on the supplied time.
* @return the time.
*/
public String giveTimestampMinusNumberOfHours(String time, int numberOfHours, String dateFormat) {
return getTime(time, dateFormat).minusHours(numberOfHours).format(getFormat(dateFormat));
}
代码示例来源:origin: allegro/hermes
public Long parse(String formattedTime) {
try {
Period period = hourFormatter.parsePeriod(formattedTime);
return LocalDateTime.now().minusHours(period.getHours()).atZone(clock.getZone()).toInstant().toEpochMilli();
} catch (IllegalArgumentException e) {
logger.info("Could not parse period. {}", e.getMessage());
}
try {
return LocalDateTime.parse(formattedTime, DateTimeFormatter.ISO_LOCAL_DATE_TIME).atZone(clock.getZone()).toInstant().toEpochMilli();
} catch (DateTimeParseException e) {
logger.info("Could not parse date. {}", e.getMessage());
}
throw new IllegalArgumentException(
"Could not parse given time. Available formats: period in hours (ex. \"-7h\") or ISO local date time"
);
}
}
代码示例来源:origin: liuyuyu/dictator
default List<DictatorConfigHistory> findLastHour() {
Weekend<DictatorConfigHistory> weekend = Weekend.of(DictatorConfigHistory.class);
weekend.weekendCriteria()
.andGreaterThanOrEqualTo(DictatorConfigHistory::getHistoryCreatedTime, LocalDateTime.now().minusHours(1));
return this.selectByExample(weekend);
}
代码示例来源:origin: allegro/hermes
private Message messageOfAge(int ageHours) {
return new JsonMessage(
MessageIdGenerator.generate(),
"{'a':'b'}".getBytes(),
now().minusHours(ageHours).toInstant(UTC).toEpochMilli()
);
}
}
代码示例来源:origin: com.scireum/sirius-kernel
private static String formatSpokenDateWithTime(Temporal date) {
// We have a time, perform some nice formatting...
LocalDateTime givenDateTime = LocalDateTime.from(date);
if (givenDateTime.isAfter(LocalDateTime.now())) {
return formatSpokenFutureDateWithTime(date, givenDateTime);
}
if (givenDateTime.isAfter(LocalDateTime.now().minusHours(12))) {
return formatSpokenRecentDateWithTime(givenDateTime);
}
if (!ChronoField.DAY_OF_MONTH.isSupportedBy(date)) {
// We don't have a date and the time difference is quite big -> simply format the time...
return getTimeFormat(getCurrentLang()).format(date);
}
return formatSpokenDate(date);
}
代码示例来源:origin: com.scireum/sirius-kernel
private static String formatSpokenRecentDateWithTime(LocalDateTime givenDateTime) {
if (givenDateTime.isAfter(LocalDateTime.now().minusMinutes(30))) {
return NLS.get("NLS.someMinutesAgo");
}
if (givenDateTime.isAfter(LocalDateTime.now().minusMinutes(59))) {
return NLS.fmtr("NLS.nMinutesAgo")
.set("minutes", Duration.between(givenDateTime, LocalDateTime.now()).toMinutes())
.format();
}
if (givenDateTime.isAfter(LocalDateTime.now().minusHours(2))) {
return NLS.get("NLS.oneHourAgo");
}
return NLS.fmtr("NLS.nHoursAgo")
.set("hours", Duration.between(givenDateTime, LocalDateTime.now()).toHours())
.format();
}
代码示例来源:origin: JoleneOL/market-manage
limitDay = 1L;
} else {
limitDay = ChronoUnit.DAYS.between(now.minusHours(getOffsetHour()).toLocalDate(), planSellOutDate) + 1;
内容来源于网络,如有侵权,请联系作者删除!