Java中OffsetTime類的getHour()方法用於從此OffsetTime實例獲取hour-of-day字段的值。
用法:
public int getHour()
參數:此方法不接受任何參數。
返回值:它返回hour-of-day,範圍為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
程序2:
// 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://docs.oracle.com/javase/8/docs/api/java/time/OffsetTime.html#getHour–
相關用法
- Java ZonedDateTime getHour()用法及代碼示例
- Java LocalTime getHour()用法及代碼示例
- Java LocalDateTime getHour()用法及代碼示例
- Java OffsetDateTime getHour()用法及代碼示例
- Java OffsetTime get()用法及代碼示例
- Java OffsetTime plus()用法及代碼示例
- Java OffsetTime until()用法及代碼示例
- Java OffsetTime from()用法及代碼示例
- Java OffsetTime now()用法及代碼示例
- Java OffsetTime with()用法及代碼示例
- Java OffsetTime minusNanos()用法及代碼示例
- Java OffsetTime compareTo()用法及代碼示例
- Java OffsetTime format()用法及代碼示例
- Java OffsetTime isBefore()用法及代碼示例
- Java OffsetTime getOffset()用法及代碼示例
注:本文由純淨天空篩選整理自gopaldave大神的英文原創作品 OffsetTime getHour() method in Java with examples。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。