📌  相关文章
📜  Java中的 OffsetTime getHour() 方法及示例

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

Java中的 OffsetTime getHour() 方法及示例

Java中 OffsetTime 类的getHour()方法用于从此 OffsetTime 实例中获取小时字段的值。

句法 :

public int getHour()

参数:此方法不接受任何参数。

返回值:返回一天中的小时,范围从 0 到 23。

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

程序 1:

// Java program to demonstrate the getHour() method
  
import java.time.OffsetTime;
  
public class GFG {
    public static void main(String[] args)
    {
  
        // Parses the time
        OffsetTime time = OffsetTime.parse("15:30:30+07:00");
  
        // gets the time
        System.out.println("Hour: " + time.getHour());
    }
}
输出:
Hour: 15

方案二

// Java program to demonstrate the getHour() method
  
import java.time.OffsetTime;
  
public class GFG {
    public static void main(String[] args)
    {
  
        // Parses the time
        OffsetTime time = OffsetTime.parse("11:30:30+06:00");
  
        // gets the time
        System.out.println("Hour: " + time.getHour());
    }
}
输出:
Hour: 11

参考:https: Java/time/OffsetTime.html#getHour–