Android獲取當前時間的3中方法總結

今天聽了一在線公開課,任務是作一個數字時鐘,其中最關鍵的天然是獲取當前的系統時間。作個簡單的記錄,以下:java

1. orm

Time time = new Time("GMT+8");
time.setToNow(); //Sets the time of the given Time object to the current time. 將事件獲取對象置爲當前時間
		
System.out.println(time.hour);
System.out.println(time.minute);
System.out.println(time.second);

2.對象

private SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
String str = sdf.format(new Date());

3.blog

Calendar calendar = Calendar.getInstance();

int hour = calendar.HOUR_OF_DAY;
int minute = calendar.MINUTE;
int second = calendar.SECOND;
相關文章
相關標籤/搜索