public void setCurrenttime() {
c = Calendar.getInstance();
hour = c.get(Calendar.HOUR_OF_DAY);
min = c.get(Calendar.MINUTE);
String am_pm;
if (hour > 12) {
am_pm = "PM";
} else {
am_pm = "AM";
}
tvDisplayHour=(TextView)findViewById(R.id.hourtext);
tvDisplayHour.setText(hour+":"+ min + " "+ am_pm);
}
我的問題是它不會在我的模擬器中設置當前時間。設置當前時間android
該代碼有什麼問題?請幫助我是Android新手。
感謝
public void setCurrenttime() {
c = Calendar.getInstance();
hour = c.get(Calendar.HOUR_OF_DAY);
min = c.get(Calendar.MINUTE);
String am_pm;
if (hour > 12) {
am_pm = "PM";
} else {
am_pm = "AM";
}
tvDisplayHour=(TextView)findViewById(R.id.hourtext);
tvDisplayHour.setText(hour+":"+ min + " "+ am_pm);
}
在這段代碼如何,我可以轉換成12小時格式?
將小時和分鐘轉換爲字符串,然後通過s tring到setText –
@NaveedAli他已經這樣做了... –