LocalTime類的plusMinutes()方法用於將指定數量的Minutes值添加到此LocalTime並將結果作為LocalTime對象返回。這一瞬間是一成不變的。計算大約在午夜結束。
用法:
public LocalTime plusMinutes(long MinutesToAdd)
參數:此方法接受單個參數MinutesToAdd,這是要添加的Minutes的值,它可以是負值。
返回值:此方法基於此時間返回一個LocalTime,並添加了Minutes。
以下示例程序旨在說明plusMinutes()方法:
示例1:
// Java program to demonstrate
// LocalTime.plusMinutes() 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 addition: "
+ time);
// add 55 Minutes using plusMinutes()
LocalTime value = time.plusMinutes(55);
// print result
System.out.println("LocalTime after addition: "
+ value);
}
}
輸出:
LocalTime before addition: 19:34:50.630 LocalTime after addition: 20:29:50.630
示例2:
// Java program to demonstrate
// LocalTime.plusMinutes() 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 addition: "
+ time);
// add -600 Minutes using plusMinutes()
LocalTime value = time.plusMinutes(-600);
// print result
System.out.println("LocalTime after addition: "
+ value);
}
}
輸出:
LocalTime before addition: 01:00:01 LocalTime after addition: 15:00:01
參考文獻: https://docs.oracle.com/javase/10/docs/api/java/time/LocalTime.html#plusMinutes(long)
相關用法
- Java OffsetDateTime plusMinutes()用法及代碼示例
- Java OffsetTime plusMinutes()用法及代碼示例
- Java ZonedDateTime plusMinutes()用法及代碼示例
- Java LocalDateTime plusMinutes()用法及代碼示例
- Java Duration plusMinutes(long)用法及代碼示例
- Java LocalTime from()用法及代碼示例
- Java LocalTime until()用法及代碼示例
- Java LocalTime with()用法及代碼示例
- Java LocalTime plus()用法及代碼示例
- Java LocalTime get()用法及代碼示例
- Java LocalTime hashCode()用法及代碼示例
- Java LocalTime ofNanoOfDay()用法及代碼示例
- Java LocalTime getHour()用法及代碼示例
- Java LocalTime minusSeconds()用法及代碼示例
- Java LocalTime compareTo()用法及代碼示例
注:本文由純淨天空篩選整理自AmanSingh2210大神的英文原創作品 LocalTime plusMinutes() method in Java with Examples。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。