How to get the current Time

前端 未结 7 2158
陌清茗
陌清茗 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

    My favorite sample:

    Time dtNow = new Time();
    dtNow.setToNow();
    int hours = dtNow.hour;
    String lsNow = dtNow.format("%Y.%m.%d %H:%M");
    String lsYMD = dtNow.toString();    // YYYYMMDDTHHMMSS
    

提交回复
热议问题