本文整理了Java中java.time.LocalTime.minusHours()
方法的一些代码示例,展示了LocalTime.minusHours()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。LocalTime.minusHours()
方法的具体详情如下:
包路径:java.time.LocalTime
类名称:LocalTime
方法名:minusHours
[英]Returns a copy of this LocalTime with the specified period in hours subtracted.
This subtracts the specified number of hours from 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
/** */
@Test
public void testPassTableWithTimeKeyCreation() {
final String creationQry = "CREATE TABLE %s (id TIME primary key, dateField TIME) " +
"WITH \"cache_name=%s, WRAP_VALUE=false\"";
Map<Time, Time> ent = new HashMap<>();
ent.put(Time.valueOf(LocalTime.now()), Time.valueOf(LocalTime.now().minusHours(1)));
ent.put(Time.valueOf(LocalTime.now().minusHours(2)), Time.valueOf(LocalTime.now().minusHours(3)));
checkInsertUpdateDelete(creationQry, "Tab2", ent);
}
代码示例来源: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 OffsetTime} 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 hours the hours to subtract, may be negative
* @return an {@code OffsetTime} based on this time with the hours subtracted, not null
*/
public OffsetTime minusHours(long hours) {
return with(time.minusHours(hours), offset);
}
代码示例来源:origin: stackoverflow.com
LocalTime lt = LocalTime.parse( "12:30" );
LocalTime earlier = lt.minusHours( 6 );
String output = earlier.toString();
代码示例来源: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();
}
内容来源于网络,如有侵权,请联系作者删除!