int hours = time.getHours();
int minutes = time.getMinutes();
int seconds = time.getSeconds();
這些功能不適用於Android 4.5,我該如何在該版本中使用它們。android-Timepicker方法getcurrenthour()已棄用,如何在android 4.5中使用getHour()?
int hours = time.getHours();
int minutes = time.getMinutes();
int seconds = time.getSeconds();
這些功能不適用於Android 4.5,我該如何在該版本中使用它們。android-Timepicker方法getcurrenthour()已棄用,如何在android 4.5中使用getHour()?
然後,以後,您檢索所需格式的時間。說,小時:分鐘( 「HH:MM」):
Long newTimeMsecValue = Calendar.getInstance().getTime().getTime();
timePicker.setOnTimeChangedListener(new
TimePicker.OnTimeChangedListener() {
@Override
public void onTimeChanged(TimePicker view, int hourOfDay, int minute) {
//NOTE: hourOfDay is always in 24h mode, not dependent of AM/PM mode!
newTimeMsecValue = new Long (((hourOfDay * 3600) + (minute * 60)) * 1000); //
}});
Calendar myCalend = Calendar.getInstance();
myCalend.setTimeInMillis(newTimeMsecValue);// value from the code above
Date calDate = myCalend.getTime();
DateFormat df = new SimpleDateFormat("HH:mm");
String humanDate = df.format(calDate);
現在:humanDate值會保持這樣的:10:21
您可以使用方法:getHour()和getMinutes()來獲得小時,然後你可以用這種方式格式化:
String date = String.format(Locale.getDefault(),「%02d:%02d」,timePicker.getHour(),timePicker.getMinute ));