Java 中的 LocalDateTime getMinute() 方法

java 8object oriented programmingprogramming

可以使用 Java 中 LocalDateTime 类中的 getMinute() 方法获取特定 LocalDateTime 的小时中的分钟数。此方法无需参数,返回 0 到 59 范围内的小时中的分钟数。

以下程序演示了此操作 −

示例

import java.time.*;
public class Demo {
   public static void main(String[] args) {
      LocalDateTime ldt = LocalDateTime.parse("2019-02-18T23:15:30");
      System.out.println("LocalDateTime 为:" + ldt);
      System.out.println("分钟为:" + ldt.getMinute());
   }
}

输出

LocalDateTime 为:2019-02-18T23:15:30
分钟为:15

现在让我们理解一下上面的程序。

首先显示 LocalDateTime。然后使用 getMinute() 方法显示 LocalDateTime 对应的分钟数。演示此操作的代码片段如下 −

LocalDateTime ldt = LocalDateTime.parse("2019-02-18T23:15:30");
System.out.println("LocalDateTime 为:" + ldt);
System.out.println("分钟为:" + ldt.getMinute());

相关文章