Java中的 OffsetTime plusMinutes() 方法及示例
OffsetTime 类的plusMinutes()方法用于将指定的 Minutes 值添加到此 OffsetTime 中,并将结果作为 OffsetTime 对象返回。这个瞬间是不变的。计算在午夜左右结束。
句法:
public OffsetTime plusMinutes(long MinutesToAdd)
参数:此方法接受单个参数MinutesToAdd ,它是要添加的 Minutes 的值,它可以是负值。
返回值:此方法基于此时间返回一个OffsetTime ,并添加了 Minutes。
下面的程序说明了 plusMinutes() 方法:
方案一:
// 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
方案二:
// 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: Java/time/OffsetTime.html#plusMinutes-long-