How to get the current Time

前端 未结 7 2167
陌清茗
陌清茗 2021-01-04 11:28

How to get the current time in Android?

When i use

int hours = java.sql.Time.this.getHours();

i get the error:

No          


        
7条回答
  •  清歌不尽
    2021-01-04 12:01

    Try this:

    int hour = Calendar.getInstance().get(Calendar.HOUR_OF_DAY);
    

    public static final int HOUR_OF_DAY Since: API Level 1 Field number for get and set indicating the hour of the day. HOUR_OF_DAY is used for the 24-hour clock. E.g., at 10:04:15.250 PM the HOUR_OF_DAY is 22.

提交回复
热议问题