獲取用戶輸入時間和日期:
DatePicker dp = (DatePicker) findViewById(R.id.datePicker);
TimePicker tp = (TimePicker) findViewById(R.id.timePicker);
int year = dp.getYear();
int month = dp.getMonth();
int date = dp.getDayOfMonth();
int hour = tp.getCurrentHour();
int min = tp.getCurrentMinute();
系統當前時間:
Calendar cal = Calendar.getInstance();
int Syear = cal.get(Calendar.YEAR);
int Smonth = cal.get(Calendar.MONTH);
int Sdate = cal.get(Calendar.DAY_OF_MONTH);
int Shour = cal.get(Calendar.HOUR_OF_DAY);
int Smin = cal.get(Calendar.MINUTE);
假如用戶與系統當前時間不同,怎麼樣得到這個時間差?日期、小時、分、秒或者毫秒。謝謝
兩個calendar當然可以做diff了,只要獲得calendar.gettimeinmillis,然後互相減,就可以得到毫秒數,剩下的自己轉換。