How to get the current Time

前端 未结 7 2074
陌清茗
陌清茗 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 11:51

    Calendar cal = Calendar.getInstance(); // get current time in a Calendar

    then you can do lots with the Calendar instance, such as get the Hours or the Minutes - like:

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

    This is recommended when you have to localize to many locales, and print data in multiple formats, or do operations on dates.

提交回复
热议问题