本文整理了Java中java.time.LocalDateTime.minusDays()
方法的一些代码示例,展示了LocalDateTime.minusDays()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。LocalDateTime.minusDays()
方法的具体详情如下:
包路径:java.time.LocalDateTime
类名称:LocalDateTime
方法名:minusDays
[英]Returns a copy of this LocalDateTime with the specified period in days subtracted.
This method subtracts the specified amount from the days field incrementing the month and year fields as necessary to ensure the result remains valid. The result is only invalid if the maximum/minimum year is exceeded.
For example, 2009-01-01 minus one day would result in 2008-12-31.
This instance is immutable and unaffected by this method call.
[中]返回此LocalDateTime的副本,并减去指定的期间(以天为单位)。
此方法从天数字段中减去指定的金额,根据需要增加月份和年份字段,以确保结果仍然有效。仅当超过最大/最小年份时,结果才无效。
例如,2009-01-01减去一天将导致2008-12-31。
此实例是不可变的,不受此方法调用的影响。
代码示例来源:origin: apache/geode
@Test
public void startDateCanFilterLines() {
LocalDateTime startDate = LocalDateTime.now().minusDays(2);
LogFilter logFilter = new LogFilter(Level.ALL, startDate, null);
assertThat(logFilter.acceptsLogEntry(Level.INFO, LocalDateTime.now())).isEqualTo(LINE_ACCEPTED);
assertThat(logFilter.acceptsLogEntry(Level.INFO, startDate)).isEqualTo(LINE_ACCEPTED);
assertThat(logFilter.acceptsLogEntry(Level.DEBUG, startDate)).isEqualTo(LINE_ACCEPTED);
assertThat(logFilter.acceptsLogEntry(Level.INFO, LocalDateTime.now().minusDays(3)))
.isEqualTo(LINE_REJECTED);
}
代码示例来源:origin: apache/geode
@Test
public void endDateCanFilterLines() {
LocalDateTime endDate = LocalDateTime.now().minusDays(2);
LogFilter logFilter = new LogFilter(Level.ALL, null, endDate);
assertThat(logFilter.acceptsLogEntry(Level.INFO, LocalDateTime.now().minusDays(3)))
.isEqualTo(LINE_ACCEPTED);
assertThat(logFilter.acceptsLogEntry(Level.INFO, endDate)).isEqualTo(LINE_ACCEPTED);
assertThat(logFilter.acceptsLogEntry(Level.DEBUG, endDate)).isEqualTo(LINE_ACCEPTED);
assertThat(logFilter.acceptsLogEntry(Level.INFO, LocalDateTime.now()))
.isEqualTo(REMAINDER_OF_FILE_REJECTED);
}
代码示例来源:origin: SonarSource/sonarqube
@Test
public void delete_ce_scanner_context_older_than_28_days() {
LocalDateTime now = LocalDateTime.now();
insertWithDate("VERY_OLD", now.minusDays(28).minusMonths(12));
insertWithDate("JUST_OLD_ENOUGH", now.minusDays(28).minusDays(1));
insertWithDate("NOT_OLD_ENOUGH", now.minusDays(28));
insertWithDate("RECENT", now.minusDays(1));
when(system2.now()).thenReturn(now.toInstant(ZoneOffset.UTC).toEpochMilli());
underTest.start();
assertThat(scannerContextExists("VERY_OLD")).isFalse();
assertThat(scannerContextExists("JUST_OLD_ENOUGH")).isFalse();
assertThat(scannerContextExists("NOT_OLD_ENOUGH")).isTrue();
assertThat(scannerContextExists("RECENT")).isTrue();
}
代码示例来源:origin: apache/geode
@Test
public void filterWorksWithLevelBasedAndTimeBasedFiltering() {
LocalDateTime startDate = LocalDateTime.now().minusDays(5);
LocalDateTime endDate = LocalDateTime.now().minusDays(2);
LogFilter logFilter = new LogFilter(Level.INFO, startDate, endDate);
assertThat(logFilter.acceptsLogEntry(Level.ERROR, LocalDateTime.now().minusDays(6)))
.isEqualTo(LINE_REJECTED);
assertThat(logFilter.acceptsLogEntry(Level.INFO, LocalDateTime.now().minusDays(6)))
.isEqualTo(LINE_REJECTED);
assertThat(logFilter.acceptsLogEntry(null)).isEqualTo(LINE_REJECTED);
assertThat(logFilter.acceptsLogEntry(Level.ERROR, LocalDateTime.now().minusDays(6)))
.isEqualTo(LINE_REJECTED);
assertThat(logFilter.acceptsLogEntry(null)).isEqualTo(LINE_REJECTED);
assertThat(logFilter.acceptsLogEntry(Level.INFO, LocalDateTime.now().minusDays(4)))
.isEqualTo(LINE_ACCEPTED);
assertThat(logFilter.acceptsLogEntry(null)).isEqualTo(LINE_ACCEPTED);
assertThat(logFilter.acceptsLogEntry(Level.ERROR, LocalDateTime.now().minusDays(1)))
.isEqualTo(REMAINDER_OF_FILE_REJECTED);
assertThat(logFilter.acceptsLogEntry(null)).isEqualTo(REMAINDER_OF_FILE_REJECTED);
assertThat(logFilter.acceptsLogEntry(Level.INFO, LocalDateTime.now().minusDays(1)))
.isEqualTo(REMAINDER_OF_FILE_REJECTED);
}
代码示例来源:origin: SonarSource/sonarqube
@Test
public void delete_activity_older_than_180_days_and_their_scanner_context() {
LocalDateTime now = LocalDateTime.now();
insertWithDate("VERY_OLD", now.minusDays(180).minusMonths(10));
insertWithDate("JUST_OLD_ENOUGH", now.minusDays(180).minusDays(1));
insertWithDate("NOT_OLD_ENOUGH", now.minusDays(180));
insertWithDate("RECENT", now.minusDays(1));
when(system2.now()).thenReturn(now.toInstant(ZoneOffset.UTC).toEpochMilli());
underTest.start();
assertThat(selectActivity("VERY_OLD").isPresent()).isFalse();
assertThat(selectTaskInput("VERY_OLD").isPresent()).isFalse();
assertThat(selectTaskCharecteristic("VERY_OLD")).hasSize(0);
assertThat(scannerContextExists("VERY_OLD")).isFalse();
assertThat(selectActivity("JUST_OLD_ENOUGH").isPresent()).isFalse();
assertThat(selectTaskInput("JUST_OLD_ENOUGH").isPresent()).isFalse();
assertThat(selectTaskCharecteristic("JUST_OLD_ENOUGH")).hasSize(0);
assertThat(scannerContextExists("JUST_OLD_ENOUGH")).isFalse();
assertThat(selectActivity("NOT_OLD_ENOUGH").isPresent()).isTrue();
assertThat(selectTaskInput("NOT_OLD_ENOUGH").isPresent()).isTrue();
assertThat(selectTaskCharecteristic("NOT_OLD_ENOUGH")).hasSize(1);
assertThat(scannerContextExists("NOT_OLD_ENOUGH")).isFalse(); // because more than 4 weeks old
assertThat(selectActivity("RECENT").isPresent()).isTrue();
assertThat(selectTaskInput("RECENT").isPresent()).isTrue();
assertThat(selectTaskCharecteristic("RECENT")).hasSize(1);
assertThat(scannerContextExists("RECENT")).isTrue();
}
代码示例来源:origin: hibernate/hibernate-orm
@Test
public void testLifecycle() {
doInJPA( this::entityManagerFactory, entityManager -> {
Person person = new Person( 1L );
LocalDateTime now = LocalDateTime.now();
person.addPhone( new Phone( PhoneType.LAND_LINE, "028-234-9876", Timestamp.valueOf( now ) ) );
person.addPhone( new Phone( PhoneType.MOBILE, "072-122-9876", Timestamp.valueOf( now.minusDays( 1 ) ) ) );
entityManager.persist( person );
} );
doInJPA( this::entityManagerFactory, entityManager -> {
Person person = entityManager.find( Person.class, 1L );
Map<PhoneType, Phone> phones = person.getPhoneRegister();
Assert.assertEquals( 2, phones.size() );
} );
}
代码示例来源:origin: hibernate/hibernate-orm
@Test
public void testLifecycle() {
doInJPA( this::entityManagerFactory, entityManager -> {
Person person = new Person( 1L );
LocalDateTime now = LocalDateTime.now();
person.addPhone(
new Phone( PhoneType.LAND_LINE, "028-234-9876", Timestamp.valueOf( now ) )
);
person.addPhone(
new Phone( PhoneType.MOBILE, "072-122-9876", Timestamp.valueOf( now.minusDays( 1 ) ) )
);
entityManager.persist( person );
} );
doInJPA( this::entityManagerFactory, entityManager -> {
Person person = entityManager.find( Person.class, 1L );
Map<Date, Phone> phones = person.getPhoneRegister();
Assert.assertEquals( 2, phones.size() );
} );
}
代码示例来源: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: hibernate/hibernate-orm
Timestamp.from(
LocalDateTime.now()
.minusDays( 1 )
.toInstant( ZoneOffset.UTC )
代码示例来源:origin: jtablesaw/tablesaw
DateTimeColumn dateTimeColumn = DateTimeColumn.create("test");
LocalDateTime beforeDate = dateTime.minusDays(1);
LocalDateTime afterDate = dateTime.plusDays(1);
before.append(beforeDate.minusDays(1));
before.append(dateTime.minusDays(1));
before.append(afterDate.minusDays(1));
代码示例来源:origin: jtablesaw/tablesaw
DateTimeColumn dateTimeColumn = DateTimeColumn.create("test");
LocalDateTime beforeDate = dateTime.minusDays(1);
LocalDateTime afterDate = dateTime.plusDays(1);
代码示例来源:origin: k0kubun/gitstar-ranking
public boolean isUpdatedWithinDays(long days)
{
LocalDateTime daysAgo = LocalDateTime.now(ZoneId.of("UTC")).minusDays(days);
return updatedAt.after(Timestamp.valueOf(daysAgo));
}
}
代码示例来源:origin: jzyong/game-server
/**
* 返回当年第一天格式
*
* @param formatter
* @return
*/
public static String getNowYearFirstDayFormat(DateTimeFormatter formatter) {
LocalDateTime ldt = LocalDateTime.ofInstant(Instant.ofEpochMilli(currentTimeMillis()), ZoneId.systemDefault());
ldt = LocalDateTime.of(ldt.minusDays(ldt.getDayOfYear() - 1).toLocalDate(), LocalTime.MIN);
return ldt.format(formatter);
}
代码示例来源:origin: jzyong/game-server
/**
* 返回当月第一天格式
*
* @param formatter
* @return
*/
public static String getNowMonthFirstDayFormat(DateTimeFormatter formatter) {
LocalDateTime ldt = LocalDateTime.ofInstant(Instant.ofEpochMilli(currentTimeMillis()), ZoneId.systemDefault());
ldt = LocalDateTime.of(ldt.minusDays(ldt.getDayOfMonth() - 1).toLocalDate(), LocalTime.MIN);
return ldt.format(formatter);
}
代码示例来源:origin: jzyong/game-server
/**@
* 返回当周第一天格式
*
* @param formatter
* @return
*/
public static String getNowWeekMondayFormat(DateTimeFormatter formatter) {
LocalDateTime ldt = LocalDateTime.ofInstant(Instant.ofEpochMilli(currentTimeMillis()), ZoneId.systemDefault());
ldt = LocalDateTime.of(ldt.minusDays(ldt.getDayOfWeek().getValue() - 1).toLocalDate(), LocalTime.MIN);
return ldt.format(formatter);
}
代码示例来源:origin: ch.sahits.game/OpenPatricianEngine
/**
* Ensure that only the most recent events are kept.
*/
private void clearCache() {
LocalDateTime now = date.getCurrentDate();
map.keySet().removeIf(next -> next.isBefore(now.minusDays(NUMBER_OF_CACHED_DAYS)));
}
代码示例来源:origin: ivannp/tradelib
public void addTransaction(Instrument instrument, LocalDateTime timeStamp, long quantity, double price, double fees) {
PortfolioData pd = portfolios.get(Portfolio.DEFAULT_NAME);
if(pd == null) {
pd = new PortfolioData(Portfolio.DEFAULT_NAME, timeStamp.minusDays(1));
}
pd.portfolio.addTransaction(instrument, timeStamp, quantity, price, fees);
}
代码示例来源:origin: codeabovelab/haven-platform
@RequestMapping(value = "/", method = GET)
public List<UiJob> list() {
LocalDateTime time = LocalDateTime.now().minusDays(1L);
return jobsManager.getJobs().stream()
.filter(ji -> ji.getInfo().getEndTime().isAfter(time))
.sorted(Comparator.comparing(jil -> jil.getInfo().getStartTime()))
.map(UiJob::toUi)
.collect(Collectors.toList());
}
代码示例来源:origin: stackoverflow.com
LocalDateTime now = new LocalDateTime();
LocalDateTime then = now.minusDays(2).minusMinutes(5);
int numberOfDaysBetween = Days.daysBetween(then, now).getDays();
LocalDateTime fullDayTime = then.plusDays(numberOfDaysBetween);
if (fullDayTime.isBefore(now)) {
numberOfDaysBetween++;
}
代码示例来源:origin: FundRequest/platform
@Test
public void setLastModifiedDate() {
final LocalDateTime expectedLastModifiedDate = LocalDateTime.now().minusDays(3);
final Request request = RequestMother.fundRequestArea51().build();
request.setLastModifiedDate(expectedLastModifiedDate);
assertThat(request.getLastModifiedDate()).isEqualTo(expectedLastModifiedDate);
}
}
内容来源于网络,如有侵权,请联系作者删除!