LocalTime类的minusNanos()方法用于从此LocalTime中减去指定的毫微秒值,并将结果作为LocalTime对象返回。这一瞬间是一成不变的。计算大约在午夜结束。
用法:
public LocalTime minusNanos(long nanosecondsToSubtract)
参数:此方法接受单个参数nanosecondsToSubtract,该参数是要减去的纳秒值,它可以是负值。
返回值:此方法基于此时间返回LocalTime,并减去纳秒。
以下示例程序旨在说明minusNanos()方法:
示例1:
// Java program to demonstrate
// LocalTime.minusNanos() method
import java.time.*;
public class GFG {
public static void main(String[] args)
{
// create a LocalTime object
LocalTime time
= LocalTime.parse("19:34:50.63");
// print LocalTime
System.out.println("LocalTime before subtraction: "
+ time);
// subtract 34000000 nanoseconds using minusNanos()
LocalTime value = time.minusNanos(34000000);
// print result
System.out.println("LocalTime after subtraction: "
+ value);
}
}
输出:
LocalTime before subtraction: 19:34:50.630 LocalTime after subtraction: 19:34:50.596
示例2:
// Java program to demonstrate
// LocalTime.minusNanos() method
import java.time.*;
public class GFG {
public static void main(String[] args)
{
// create a LocalTime object
LocalTime time
= LocalTime.parse("01:00:01");
// print LocalTime
System.out.println("LocalTime before subtraction: "
+ time);
// subtract 971200000 nanoseconds using minusNanos()
LocalTime value = time.minusNanos(971200000);
// print result
System.out.println("LocalTime after subtraction: "
+ value);
}
}
输出:
LocalTime before subtraction: 01:00:01 LocalTime after subtraction: 01:00:00.028800
参考文献: https://docs.oracle.com/javase/10/docs/api/java/time/LocalTime.html#minusNanos(long)
相关用法
- Java OffsetTime minusNanos()用法及代码示例
- Java ZonedDateTime minusNanos()用法及代码示例
- Java Instant minusNanos()用法及代码示例
- Java OffsetDateTime minusNanos()用法及代码示例
- Java Duration minusNanos(long)用法及代码示例
- Java LocalTime until()用法及代码示例
- Java LocalTime from()用法及代码示例
- Java LocalTime plus()用法及代码示例
- Java LocalTime get()用法及代码示例
- Java LocalTime with()用法及代码示例
- Java LocalTime withMinute()用法及代码示例
- Java LocalTime range()用法及代码示例
- Java LocalTime plusHours()用法及代码示例
- Java LocalTime withSecond()用法及代码示例
- Java LocalTime minusSeconds()用法及代码示例
注:本文由纯净天空筛选整理自AmanSingh2210大神的英文原创作品 LocalTime minusNanos() method in Java with Examples。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。