日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

date.gethour_Java LocalDateTime类| 带示例的getHour()方法

發布時間:2025/3/11 72 豆豆
生活随笔 收集整理的這篇文章主要介紹了 date.gethour_Java LocalDateTime类| 带示例的getHour()方法 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

date.gethour

LocalDateTime類getHour()方法 (LocalDateTime Class getHour() method)

  • getHour() method is available in java.time package.

    getHour()方法在java.time包中可用。

  • getHour() method is used to get an hour-of-day field value from this date-time object.

    getHour()方法用于從該日期時間對象獲取一天中的小時值。

  • getHour() method is a non-static method, it is accessible with the class object only and if we try to access the method with the class name then we will get an error.

    getHour()方法是一個非靜態方法,只能通過類對象訪問,如果嘗試使用類名稱訪問該方法,則會收到錯誤消息。

  • getHour() method does not throw an exception at the time of getting an hour of the day.

    在一天中的一個小時內, getHour()方法不會引發異常。

Syntax:

句法:

public int getHour();

Parameter(s):

參數:

  • None

    沒有

Return value:

返回值:

The return type of this method is int, it returns the value hour-of-day field of this object and the number of hours in a day starts from 0 and ends at 23.

此方法的返回類型為int ,它返回此對象的value-of-day字段,并且一天中的小時數從0開始,以23結尾。

Example:

例:

// Java program to demonstrate the example // of getHour() method of LocalDateTimeimport java.time.*;public class GetHourOfLocalDateTime {public static void main(String args[]) {// Instantiates two LocalDateTimeLocalDateTime da_ti1 = LocalDateTime.parse("2005-10-05T10:10:10");LocalDateTime da_ti2 = LocalDateTime.now();// Display da_ti1, da_ti2System.out.println("LocalDateTime da_ti1 and da_ti2: ");System.out.println("da_ti1: " + da_ti1);System.out.println("da_ti2: " + da_ti2);System.out.println();// Here, this method returns the// field value hour-of-day from // this date-time object (da_ti1)int hod = da_ti1.getHour();// Display hodSystem.out.println("da_ti1.getHour(): " + hod);// Here, this method returns the // field value hour-of-day from // this date-time object (da_ti2)hod = da_ti2.getHour();// Display hodSystem.out.println("da_ti2.getHour(): " + hod);} }

Output

輸出量

LocalDateTime da_ti1 and da_ti2: da_ti1: 2005-10-05T10:10:10 da_ti2: 2020-06-05T02:54:33.968481da_ti1.getHour(): 10 da_ti2.getHour(): 2

翻譯自: https://www.includehelp.com/java/localdatetime-gethour-method-with-example.aspx

date.gethour

創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎

總結

以上是生活随笔為你收集整理的date.gethour_Java LocalDateTime类| 带示例的getHour()方法的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。