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