📜  Java中的 LocalTime plusMinutes() 方法及示例

📅  最后修改于: 2022-05-13 01:55:46.837000             🧑  作者: Mango

Java中的 LocalTime plusMinutes() 方法及示例

LocalTimeplusMinutes()方法用于将指定的 Minutes 值添加到此 LocalTime 中,并将结果作为 LocalTime 对象返回。这个瞬间是不变的。计算在午夜左右结束。

句法:

public LocalTime plusMinutes(long MinutesToAdd)

参数:此方法接受单个参数MinutesToAdd ,它是要添加的 Minutes 的值,它可以是负值。

返回值:此方法基于此时间返回一个LocalTime ,并添加了 Minutes。

下面的程序说明了 plusMinutes() 方法:

方案一:

// 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

方案二:

// 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: Java/time/LocalTime.html#plusMinutes(long)