本文整理汇总了Java中java.time.LocalDateTime.plusHours方法的典型用法代码示例。如果您正苦于以下问题:Java LocalDateTime.plusHours方法的具体用法?Java LocalDateTime.plusHours怎么用?Java LocalDateTime.plusHours使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.time.LocalDateTime
的用法示例。
在下文中一共展示了LocalDateTime.plusHours方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: test_plusHours_one
import java.time.LocalDateTime; //导入方法依赖的package包/类
@Test
public void test_plusHours_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.plusHours(1);
if ((i + 1) % 24 == 0) {
d = d.plusDays(1);
}
assertEquals(t.toLocalDate(), d);
assertEquals(t.getHour(), (i + 1) % 24);
}
}
示例2: test_plusHours_fromZero
import java.time.LocalDateTime; //导入方法依赖的package包/类
@Test
public void test_plusHours_fromZero() {
LocalDateTime base = TEST_2007_07_15_12_30_40_987654321.with(LocalTime.MIDNIGHT);
LocalDate d = base.toLocalDate().minusDays(3);
LocalTime t = LocalTime.of(21, 0);
for (int i = -50; i < 50; i++) {
LocalDateTime dt = base.plusHours(i);
t = t.plusHours(1);
if (t.getHour() == 0) {
d = d.plusDays(1);
}
assertEquals(dt.toLocalDate(), d);
assertEquals(dt.toLocalTime(), t);
}
}
示例3: init
import java.time.LocalDateTime; //导入方法依赖的package包/类
@Override public void init() {
int noOfValues = 24 * 60;
LocalDateTime start = LocalDateTime.now();
LocalDateTime end = start.plusHours(24);
List<TYChartItem> tyData1 = new ArrayList<>();
for (int i = 0 ; i < noOfValues ; i++) {
tyData1.add(new TYChartItem(start.plusMinutes(i), RND.nextDouble() * 12 + RND.nextDouble() * 6, "P" + i, COLORS[RND.nextInt(3)]));
}
tySeries1 = new XYSeries(tyData1, ChartType.LINE, Color.RED, Color.rgb(255, 0, 0, 0.5));
tySeries1.setSymbolsVisible(false);
// XYChart
Converter tempConverter = new Converter(TEMPERATURE, CELSIUS); // Type Temperature with BaseUnit Celsius
double tempFahrenheitMin = tempConverter.convert(0, FAHRENHEIT);
double tempFahrenheitMax = tempConverter.convert(20, FAHRENHEIT);
xAxisBottom = createBottomTimeAxis(start, end, "HH:mm", true);
yAxisLeft = createLeftYAxis(0, 20, true);
yAxisRight = createRightYAxis(tempFahrenheitMin, tempFahrenheitMax, false);
tyChart = new XYChart<>(new XYPane(tySeries1), yAxisLeft, yAxisRight, xAxisBottom);
tyChart.setPrefSize(400, 200);
}
示例4: getTimestamp
import java.time.LocalDateTime; //导入方法依赖的package包/类
public Timestamp getTimestamp(String daysS, String hoursS, String minutesS){
daysS = daysS==null || daysS.equals("") ? "0" : daysS;
hoursS = hoursS==null || hoursS.equals("") ? "0" : hoursS;
minutesS = minutesS==null || minutesS.equals("") ? "0" : minutesS;
Integer days = Integer.parseInt(daysS);
Integer hours = Integer.parseInt(hoursS);
Integer minutes = Integer.parseInt(minutesS);
if(days==0 && hours==0 && minutes==0){
days = 10000;
hours = 11;
minutes = 59;
}
days = days > 10000 ? 10000 : days;
hours = hours%24;
minutes = minutes%60;
LocalDateTime localDateTime = LocalDateTime.now();
localDateTime = localDateTime.plusDays(days);
localDateTime = localDateTime.plusHours(hours);
localDateTime = localDateTime.plusMinutes(minutes);
return Timestamp.valueOf(localDateTime);
}
示例5: test_plusHours_fromOne
import java.time.LocalDateTime; //导入方法依赖的package包/类
@Test
public void test_plusHours_fromOne() {
LocalDateTime base = TEST_2007_07_15_12_30_40_987654321.with(LocalTime.of(1, 0));
LocalDate d = base.toLocalDate().minusDays(3);
LocalTime t = LocalTime.of(22, 0);
for (int i = -50; i < 50; i++) {
LocalDateTime dt = base.plusHours(i);
t = t.plusHours(1);
if (t.getHour() == 0) {
d = d.plusDays(1);
}
assertEquals(dt.toLocalDate(), d);
assertEquals(dt.toLocalTime(), t);
}
}
示例6: raidsCollide
import java.time.LocalDateTime; //导入方法依赖的package包/类
@Test
public void raidsCollide() throws Exception {
final ClockService currentTimeService = new ClockService();
currentTimeService.setMockTime(LocalTime.of(10, 0));
LocalDateTime startOne = currentTimeService.getCurrentDateTime();
LocalDateTime endOne = startOne.plusHours(1);
LocalDateTime startTwo = currentTimeService.getCurrentDateTime().minusMinutes(1);
LocalDateTime endTwo = startTwo.plusHours(1);
assertThat(Utils.raidsCollide(endOne, false, endTwo, false), is(true));
assertThat(Utils.raidsCollide(endTwo, false, endOne, false), is(true));
startOne = currentTimeService.getCurrentDateTime();
endOne = startOne.plusMinutes(10);
startTwo = currentTimeService.getCurrentDateTime().plusMinutes(11);
endTwo = startTwo.plusHours(1);
assertThat(Utils.raidsCollide(endOne, false, endTwo, false), is(false));
assertThat(Utils.raidsCollide(endTwo, false, endOne, false), is(false));
}
示例7: computeFirstResetTime
import java.time.LocalDateTime; //导入方法依赖的package包/类
protected static LocalDateTime computeFirstResetTime(LocalDateTime baseTime, int time, TimeUnit unit) {
if (unit != TimeUnit.SECONDS && unit != TimeUnit.MINUTES && unit != TimeUnit.HOURS && unit != TimeUnit.DAYS) {
throw new IllegalArgumentException();
}
LocalDateTime t = baseTime;
switch (unit) {
case DAYS:
t = t.plusDays(1).withHour(0).withMinute(0).withSecond(0).withNano(0);
break;
case HOURS:
if (24 % time == 0) {
t = t.plusHours(time - t.getHour() % time);
} else {
t = t.plusHours(1);
}
t = t.withMinute(0).withSecond(0).withNano(0);
break;
case MINUTES:
if (60 % time == 0) {
t = t.plusMinutes(time - t.getMinute() % time);
} else {
t = t.plusMinutes(1);
}
t = t.withSecond(0).withNano(0);
break;
case SECONDS:
if (60 % time == 0) {
t = t.plusSeconds(time - t.getSecond() % time);
} else {
t = t.plusSeconds(1);
}
t = t.withNano(0);
break;
}
return t;
}
示例8: testClacPlus
import java.time.LocalDateTime; //导入方法依赖的package包/类
/**
* 时间运算,计算完成后会返回新的对象,并不会改变原来的时间
*/
@Test
public void testClacPlus() {
LocalDateTime ldt = LocalDateTime.now();
System.out.println(ldt);
// 加: 天
LocalDateTime day = ldt.plusDays(1);
System.out.println("day: " + day);
// 加: 小时
LocalDateTime hours = ldt.plusHours(1);
System.out.println("hours: " + hours);
// 加: 分钟
LocalDateTime minutes = ldt.plusMinutes(1);
System.out.println("minutes: " + minutes);
// 加: 月
LocalDateTime months = ldt.plusMonths(1);
System.out.println("months: " + months);
// 加: 纳秒
LocalDateTime nanos = ldt.plusNanos(1);
System.out.println("nanos: " + nanos);
// 加: 秒
LocalDateTime seconds = ldt.plusSeconds(1);
System.out.println("seconds: " + seconds);
// 加: 周
LocalDateTime weeks = ldt.plusWeeks(1);
System.out.println("weeks: " + weeks);
// 加: 年
LocalDateTime years = ldt.plusYears(1);
System.out.println("years: " + years);
System.out.println(ldt);
}
示例9: addHour
import java.time.LocalDateTime; //导入方法依赖的package包/类
/**
* 计算 hour 小时后的时间
*
* @param date 长日期
* @param hour 增加的小时数
* @return 增加后的日期
*/
public static LocalDateTime addHour(LocalDateTime date, int hour) {
return date.plusHours(hour);
}