本文整理了Java中java.time.LocalTime.plusHours()
方法的一些代码示例,展示了LocalTime.plusHours()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。LocalTime.plusHours()
方法的具体详情如下:
包路径:java.time.LocalTime
类名称:LocalTime
方法名:plusHours
[英]Returns a copy of this LocalTime with the specified period in hours added.
This adds the specified number of hours to this time, returning a new time. The calculation wraps around midnight.
This instance is immutable and unaffected by this method call.
[中]返回此LocalTime的副本,并添加指定的时间段(以小时为单位)。
这会将指定的小时数添加到此时间,并返回一个新时间。计算时间大约在午夜。
此实例是不可变的,不受此方法调用的影响。
代码示例来源:origin: apache/ignite
/**
* Tests updating of all Date and Time fields.
*/
@Test
public void testUpdateAllFields() {
EntityWithDateTimeFields expEntity = new EntityWithDateTimeFields(entity);
expEntity.setLocalTime(expEntity.getLocalTime().plusHours(1));
expEntity.setLocalDate(expEntity.getLocalDate().plusDays(1));
expEntity.setLocalDateTime(LocalDateTime.of(expEntity.getLocalDate(), expEntity.getLocalTime()));
SqlFieldsQuery qry = new SqlFieldsQuery(
"update EntityWithDateTimeFields set locTime = ?, locDate = ?, locDateTime = ? where id = ?"
).setArgs(expEntity.getLocalTime(), expEntity.getLocalDate(), expEntity.getLocalDateTime(), entity.getId());
List<List<?>> qryResults = cache.query(qry).getAll();
assertEquals(1, qryResults.size());
assertEquals(1L, qryResults.get(0).get(0));
assertEquals(expEntity, cache.get(expEntity.getId()));
}
代码示例来源:origin: biezhi/learn-java8
public static void main(String[] args) {
// 创建一个LocalTime实例
LocalTime localTime = LocalTime.now();
// 使用指定的时分秒和纳秒来新建对象
LocalTime localTime2 = LocalTime.of(21, 30, 59, 11001);
// 3小时后
LocalTime localTimeLater = localTime.plusHours(3);
// 3小时前
LocalTime localTimeEarlier = localTime.minusHours(3);
System.out.println("localTime : " + localTime);
System.out.println("localTime2 : " + localTime2);
System.out.println("localTimeLater : " + localTimeLater);
System.out.println("localTimeEarlier: " + localTimeEarlier);
}
}
代码示例来源:origin: com.github.seratch/java-time-backport
/**
* Returns a copy of this {@code LocalTime} with the specified period in hours subtracted.
* <p>
* This subtracts the specified number of hours from this time, returning a new time.
* The calculation wraps around midnight.
* <p>
* This instance is immutable and unaffected by this method call.
*
* @param hoursToSubtract the hours to subtract, may be negative
* @return a {@code LocalTime} based on this time with the hours subtracted, not null
*/
public LocalTime minusHours(long hoursToSubtract) {
return plusHours(-(hoursToSubtract % HOURS_PER_DAY));
}
代码示例来源:origin: sta-szek/pojo-tester
@Override
protected LocalTime increaseValue(final LocalTime value, final Class<?> type) {
return value.plusHours(1);
}
代码示例来源:origin: stackoverflow.com
LocalTime start = LocalTime.parse( "08:00" );
int hours = 2;
LocalTime time = start;
for ( int i = 0 ; i <= hours ; i++ ) {
String output = time.toString();
// Set up next loop.
time = time.plusHours( 1 );
}
代码示例来源:origin: com.github.seratch/java-time-backport
/**
* Returns a copy of this {@code OffsetTime} with the specified period in hours added.
* <p>
* This adds the specified number of hours to this time, returning a new time.
* The calculation wraps around midnight.
* <p>
* This instance is immutable and unaffected by this method call.
*
* @param hours the hours to add, may be negative
* @return an {@code OffsetTime} based on this time with the hours added, not null
*/
public OffsetTime plusHours(long hours) {
return with(time.plusHours(hours), offset);
}
代码示例来源:origin: stackoverflow.com
LocalTime lt = LocalTime.parse( "07:30" );
LocalTime ltLater = lt.plusHours( 2 );
String output = ltLater.toString(); // 09:30
代码示例来源:origin: stackoverflow.com
LocalTime now = LocalTime.now();
LocalTime start = new LocalTime( 13, 0, 0, 0 );
LocalTime stop = start.plusHours( 11 );
System.out.println( "now: " + now );
System.out.println( "start: " + start );
System.out.println( "stop: " + stop );
if ( now.isAfter( start ) ) {
System.out.println( "After start" );
}
if ( now.isBefore( stop ) ) {
System.out.println( "Before stop" );
}
代码示例来源:origin: xiangwbs/springboot
/**
* 获取n小时前/后的时间字符串
* 返回格式:HH:mm
*
* @param time 格式 HH:mm
* @param h
* @return
*/
public static String timeAddMinusHours(String time, int h) {
LocalTime localTime = LocalTime.parse(time);
LocalTime newTime = h >= 0 ? localTime.plusHours(h) : localTime.minusHours(Math.abs(h));
return newTime.toString();
}
代码示例来源:origin: stackoverflow.com
LocalTime localTime = new LocalTime("17:46");
LocalTime newTime = localTime.plusHours(1).plusMinutes(1);
System.out.println(newTime.toString("HH:mm"));
代码示例来源:origin: stackoverflow.com
LocalTime t1 = LocalTime.of(9, 0); // 09:00
LocalTime t2 = LocalTime.of(2, 30); // 02:30
LocalTime total = t1.plusHours(t2.getHour())
.plusMinutes(t2.getMinute()); // 11:30
代码示例来源:origin: com.guestful.module/guestful.module.jsr310-extensions
public static LocalTime roundUpMinutes(LocalTime time, int step) {
int mins = time.getMinute();
time = time.withSecond(0).withNano(0);
if (mins % step == 0) return time;
if (60 % step != 0) throw new IllegalArgumentException("Invalid step: " + step);
mins = mins + step - (mins % step);
return mins < 60 ? time.withMinute(mins) : time.plusHours(1).withMinute(mins - 60);
}
代码示例来源:origin: shengsiyuan/jdk8
System.out.println(time);
LocalTime time2 = time.plusHours(3).plusMinutes(20);
System.out.println(time2);
代码示例来源:origin: xiangwbs/springboot
LocalTime newSpecificTime = specificTime.plusHours(2);// 增加2小时
LocalTime timeKolkata = LocalTime.now(ZoneId.of("Asia/Kolkata"));
LocalTime specificSecondTime = LocalTime.ofSecondOfDay(1);// 00:00:01
代码示例来源:origin: com.healthmarketscience.jackcess/jackcess
@Override
protected Value eval3(EvalContext ctx, Value param1, Value param2, Value param3) {
int hours = param1.getAsLongInt(ctx);
int minutes = param2.getAsLongInt(ctx);
int seconds = param3.getAsLongInt(ctx);
// we have to construct incrementatlly to handle out of range values
LocalTime lt = ColumnImpl.BASE_LT.plusHours(hours).plusMinutes(minutes)
.plusSeconds(seconds);
return ValueSupport.toValue(lt);
}
});
代码示例来源:origin: com.github.seratch/java-time-backport
case SECONDS: return plusSeconds(amountToAdd);
case MINUTES: return plusMinutes(amountToAdd);
case HOURS: return plusHours(amountToAdd);
case HALF_DAYS: return plusHours((amountToAdd % 2) * 12);
代码示例来源:origin: stackoverflow.com
@Override
LocalTime increment(LocalTime time, int steps) {
return time.plusHours(steps);
代码示例来源:origin: com.github.seratch/java-time-backport
case MINUTE_OF_HOUR: return withMinute((int) newValue);
case MINUTE_OF_DAY: return plusMinutes(newValue - (hour * 60 + minute));
case HOUR_OF_AMPM: return plusHours(newValue - (hour % 12));
case CLOCK_HOUR_OF_AMPM: return plusHours((newValue == 12 ? 0 : newValue) - (hour % 12));
case HOUR_OF_DAY: return withHour((int) newValue);
case CLOCK_HOUR_OF_DAY: return withHour((int) (newValue == 24 ? 0 : newValue));
case AMPM_OF_DAY: return plusHours((newValue - (hour / 12)) * 12);
代码示例来源:origin: sta-szek/pojo-tester
@TestFactory
Stream<DynamicTest> Should_Return_True_Or_False_Whether_Values_Are_Different_Or_Not() {
final LocalTime date1 = LocalTime.now();
final LocalTime date2 = LocalTime.now()
.plusHours(1);
return Stream.of(new AreDifferentCase(null, null, false),
new AreDifferentCase(date1, date1, false),
new AreDifferentCase(null, date2, true),
new AreDifferentCase(date1, null, true),
new AreDifferentCase(date1, date2, true))
.map(value -> dynamicTest(getDefaultDisplayName(value.value1 + " " + value.value2),
Should_Return_True_Or_False_Whether_Values_Are_Different_Or_Not(value)));
}
代码示例来源:origin: com.bitplan.gui/com.bitplan.javafx
@Override public void init() {
TimeSection gardenLightOn = TimeSectionBuilder.create()
.start(LocalTime.now().plusHours(1))
.stop(LocalTime.now().plusHours(3))
.color(Color.rgb(200, 100, 0, 0.1))
.highlightColor(Color.rgb(222, 111, 0, 0.75))
.stop(LocalTime.now().plusHours(1))
.color(Color.rgb(200, 0, 0, 0.1))
.highlightColor(Color.rgb(222, 0, 0, 0.75))
内容来源于网络,如有侵权,请联系作者删除!