Java中OffsetTime類的minusNanos()方法返回該OffsetTime的副本,其中減去了參數中的指定Nanos。
用法:
public OffsetTime minusNanos(long Nanos)
參數:此方法接受要減去的Nanos的單個參數Nanos。可能是負麵的。
返回值:它基於此時間返回OffsetTime並減去Nanos,並且它不為null。
以下示例程序旨在說明minusNanos()方法:
示例1:
// Java program to demonstrate the minusNanos() method
import java.time.OffsetTime;
public class GFG {
public static void main(String[] args)
{
// Parses the time
OffsetTime time = OffsetTime.parse("11:10:10+05:05");
// Specified Nanos subtracted
System.out.println("After subtraction, time is: " + time.minusNanos(5));
}
}
輸出:
After subtraction, time is: 11:10:09.999999995+05:05
程序2:
// Java program to demonstrate the minusNanos() method
import java.time.OffsetTime;
public class GFG {
public static void main(String[] args)
{
// Parses the time
OffsetTime time = OffsetTime.parse("11:10:10+05:05");
// Specified Nanos subtracted
System.out.println("After subtraction, time is: " + time.minusNanos(-5));
}
}
輸出:
After subtraction, time is: 11:10:10.000000005+05:05
參考: https://docs.oracle.com/javase/8/docs/api/java/time/OffsetTime.html#minusNanos-long-
相關用法
- Java OffsetDateTime minusNanos()用法及代碼示例
- Java ZonedDateTime minusNanos()用法及代碼示例
- Java Instant minusNanos()用法及代碼示例
- Java LocalTime minusNanos()用法及代碼示例
- Java Duration minusNanos(long)用法及代碼示例
- Java OffsetTime until()用法及代碼示例
- Java OffsetTime from()用法及代碼示例
- Java OffsetTime get()用法及代碼示例
- Java OffsetTime plus()用法及代碼示例
- Java OffsetTime now()用法及代碼示例
- Java OffsetTime with()用法及代碼示例
- Java OffsetTime format()用法及代碼示例
- Java OffsetTime getNano()用法及代碼示例
- Java OffsetTime compareTo()用法及代碼示例
- Java OffsetTime equals()用法及代碼示例
注:本文由純淨天空篩選整理自gopaldave大神的英文原創作品 OffsetTime minusNanos() method in Java with examples。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。