OffsetTime類的plusSeconds()方法用於將指定的秒數值添加到此OffsetTime並將結果作為OffsetTime對象返回。這一瞬間是一成不變的。計算大約在午夜結束。
用法:
public OffsetTime plusSeconds(long SecondsToAdd)
參數:此方法接受單個參數SecondsToAdd,該參數是要添加的Seconds的值,它可以是負值。
返回值:此方法基於此時間返回OffsetTime並添加了Seconds。
以下示例程序旨在說明plusSeconds()方法:
示例1:
// Java program to demonstrate
// OffsetTime.plusSeconds() method
import java.time.*;
public class GFG {
public static void main(String[] args)
{
// create a OffsetTime object
OffsetTime time
= OffsetTime.parse("21:15:10+11:10");
// print OffsetTime
System.out.println("OffsetTime before addition: "
+ time);
// add 200 Seconds using plusSeconds()
OffsetTime value = time.plusSeconds(200);
// print result
System.out.println("OffsetTime after addition: "
+ value);
}
}
輸出:
OffsetTime before addition: 21:15:10+11:10 OffsetTime after addition: 21:18:30+11:10
示例2:
// Java program to demonstrate
// OffsetTime.plusSeconds() method
import java.time.*;
public class GFG {
public static void main(String[] args)
{
// create a OffsetTime object
OffsetTime time
= OffsetTime.parse("14:25:10+01:10");
// print OffsetTime
System.out.println("OffsetTime before addition: "
+ time);
// add -3400 Seconds using plusSeconds()
OffsetTime value = time.plusSeconds(-3400);
// print result
System.out.println("OffsetTime after addition: "
+ value);
}
}
輸出:
OffsetTime before addition: 14:25:10+01:10 OffsetTime after addition: 13:28:30+01:10
參考文獻: https://docs.oracle.com/javase/8/docs/api/java/time/OffsetTime.html#plusSeconds-long-
相關用法
- Java OffsetTime get()用法及代碼示例
- Java OffsetTime from()用法及代碼示例
- Java OffsetTime until()用法及代碼示例
- Java OffsetTime plus()用法及代碼示例
- Java OffsetTime with()用法及代碼示例
- Java OffsetTime now()用法及代碼示例
- Java OffsetTime isBefore()用法及代碼示例
- Java OffsetTime format()用法及代碼示例
- Java OffsetTime minus()用法及代碼示例
- Java OffsetTime minusSeconds()用法及代碼示例
- Java OffsetTime minusMinutes()用法及代碼示例
- Java OffsetTime toLocalTime()用法及代碼示例
- Java OffsetTime isEqual()用法及代碼示例
- Java OffsetTime range()用法及代碼示例
- Java OffsetTime minusHours()用法及代碼示例
注:本文由純淨天空篩選整理自gopaldave大神的英文原創作品 OffsetTime plusSecond() method in Java with Examples。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。