本文整理汇总了Java中java.time.LocalDateTime.minusHours方法的典型用法代码示例。如果您正苦于以下问题:Java LocalDateTime.minusHours方法的具体用法?Java LocalDateTime.minusHours怎么用?Java LocalDateTime.minusHours使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.time.LocalDateTime
的用法示例。
在下文中一共展示了LocalDateTime.minusHours方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import java.time.LocalDateTime; //导入方法依赖的package包/类
public static void main(String[] args) {
/*LocalDate date = LocalDate.of(2014, Month.JANUARY, 20);
System.out.println(date);
date = date.plusDays(2);
System.out.println(date);
date = date.plusWeeks(1);
System.out.println(date);
date = date.plusMonths(1);
System.out.println(date);
date = date.plusYears(5);
System.out.println(date);*/
LocalDate date = LocalDate.of(2020, Month.JANUARY, 20);
LocalTime time = LocalTime.of(5, 15);
LocalDateTime dateTime = LocalDateTime.of(date, time);
System.out.println(dateTime);
dateTime = dateTime.minusDays(1);
System.out.println(dateTime);
dateTime = dateTime.minusHours(10);
System.out.println(dateTime);
dateTime = dateTime.minusSeconds(30);
System.out.println(dateTime);
}
示例2: test_minusHours_one
import java.time.LocalDateTime; //导入方法依赖的package包/类
@Test
public void test_minusHours_one() {
LocalDateTime t =TEST_2007_07_15_12_30_40_987654321.with(LocalTime.MIDNIGHT);
LocalDate d = t.toLocalDate();
for (int i = 0; i < 50; i++) {
t = t.minusHours(1);
if (i % 24 == 0) {
d = d.minusDays(1);
}
assertEquals(t.toLocalDate(), d);
assertEquals(t.getHour(), (((-i + 23) % 24) + 24) % 24);
}
}
示例3: test_minusHours_fromZero
import java.time.LocalDateTime; //导入方法依赖的package包/类
@Test
public void test_minusHours_fromZero() {
LocalDateTime base = TEST_2007_07_15_12_30_40_987654321.with(LocalTime.MIDNIGHT);
LocalDate d = base.toLocalDate().plusDays(2);
LocalTime t = LocalTime.of(3, 0);
for (int i = -50; i < 50; i++) {
LocalDateTime dt = base.minusHours(i);
t = t.minusHours(1);
if (t.getHour() == 23) {
d = d.minusDays(1);
}
assertEquals(dt.toLocalDate(), d, String.valueOf(i));
assertEquals(dt.toLocalTime(), t);
}
}
示例4: test_minusHours_fromOne
import java.time.LocalDateTime; //导入方法依赖的package包/类
@Test
public void test_minusHours_fromOne() {
LocalDateTime base = TEST_2007_07_15_12_30_40_987654321.with(LocalTime.of(1, 0));
LocalDate d = base.toLocalDate().plusDays(2);
LocalTime t = LocalTime.of(4, 0);
for (int i = -50; i < 50; i++) {
LocalDateTime dt = base.minusHours(i);
t = t.minusHours(1);
if (t.getHour() == 23) {
d = d.minusDays(1);
}
assertEquals(dt.toLocalDate(), d, String.valueOf(i));
assertEquals(dt.toLocalTime(), t);
}
}
示例5: getAmountOfActiveProcessesPerUser
import java.time.LocalDateTime; //导入方法依赖的package包/类
@RequestMapping(value = "processes/count/started/{hoursbefore}", method = RequestMethod.GET)
public @ResponseBody Callable<Long> getAmountOfActiveProcessesPerUser(
final HttpServletRequest request, @PathVariable("hoursbefore") final Long hoursbefore) {
return () -> {
final LocalDateTime end = LocalDateTime.now();
final LocalDateTime start = end.minusHours(hoursbefore);
return processService.getAmountOfStartedProcessesBetween(start, end).get();
};
}
示例6: getAmountOfFinishedProcessesPerUser
import java.time.LocalDateTime; //导入方法依赖的package包/类
@RequestMapping(value = "processes/count/finished/{hoursbefore}", method = RequestMethod.GET)
public @ResponseBody Callable<Long> getAmountOfFinishedProcessesPerUser(
final HttpServletRequest request, @PathVariable("hoursbefore") final Long hoursbefore) {
return () -> {
final LocalDateTime end = LocalDateTime.now();
final LocalDateTime start = end.minusHours(hoursbefore);
return processService.getAmountOfFinishedProcessesBetween(start, end).get();
};
}
示例7: testGernerate
import java.time.LocalDateTime; //导入方法依赖的package包/类
@Ignore
@Test
public void testGernerate() throws IOException {
LocalDateTime localDateTime1 = LocalDateTime.of(2013, 12, 31, 23, 59, 59);
LocalDateTime localDateTime2 = LocalDateTime.of(2017, 1, 1, 0, 0, 0);
LocalDateTime date1 = LocalDateTime.of(2003, 12, 31, 23, 59, 59);
LocalDateTime date2 = LocalDateTime.of(2007, 1, 1, 0, 0, 0);
List<String> lines = new ArrayList<>();
lines.add("<?xml version='1.0' encoding='UTF-8'?>");
lines.add("<dataset>");
for (Long id = 1L; id <= 1000; id++) {
String line = "<TEST_DATES_ENTITY ID='" + id + "'";
line += " LOCAL_DATE_TIME1='" + localDateTime1.format(DATE_PATTERN) + "'";
line += " LOCAL_DATE_TIME2='" + localDateTime2.format(DATE_PATTERN) + "'";
line += " DATE1='" + date1.format(DATE_PATTERN) + "'";
line += " DATE2='" + date2.format(DATE_PATTERN) + "' />";
lines.add(line);
localDateTime1 = localDateTime1.plusDays(1L);
localDateTime2 = localDateTime2.minusHours(6L);
date1 = date1.plusDays(1L);
date2 = date2.minusHours(6L);
}
lines.add("</dataset>");
Path file = Paths.get("src/test/resources/date-dataset.xml");
Files.write(file, lines, Charset.forName("UTF-8"));
}
示例8: getListLockMore24Heure
import java.time.LocalDateTime; //导入方法依赖的package包/类
/**
* @return la liste des locks de l'application
*/
public List<LockCandidat> getListLockMore24Heure(){
LocalDateTime timeLess24 = LocalDateTime.now();
timeLess24 = timeLess24.minusHours(24);
return lockCandidatRepository.findByDatLockBefore(timeLess24);
}
示例9: testClac
import java.time.LocalDateTime; //导入方法依赖的package包/类
/**
* 时间计算,减法操作
*/
@Test
public void testClac(){
LocalDateTime ldt = LocalDateTime.now();
System.out.println(ldt);
// 减: 天
LocalDateTime days = ldt.minusDays(1);
System.out.println("day: " + days);
// 减: 小时
LocalDateTime hours = ldt.minusHours(1);
System.out.println("hours: " + hours);
// 减: 分钟
LocalDateTime minutes = ldt.minusMinutes(1);
System.out.println("minutes: " + minutes);
// 减: 月
LocalDateTime months = ldt.minusMonths(1);
System.out.println("months: " + months);
// 减: 纳秒
LocalDateTime nanos = ldt.minusNanos(1);
System.out.println("nanos: " + nanos);
// 减: 秒
LocalDateTime seconds = ldt.minusSeconds(1);
System.out.println("seconds: " + seconds);
// 减: 周
LocalDateTime weeks = ldt.minusWeeks(1);
System.out.println("weeks: " + weeks);
// 减: 年
LocalDateTime years = ldt.minusYears(1);
System.out.println("years: " + years);
System.out.println(ldt);
}