我正在開發一個項目,其中需要根據當前時間更改預訂訂單的時間。我需要做的是我想獲得當前時間,並且必須生成時間字符串列表並將其填充到微調器中。例如。我的開始和結束時間是上午11點到下午2點,目前時間是下午12點30分。所以我需要把目前的時間和生成一個30分鐘的時間間隔列表視圖直到結束時間。所以那將是1:00,1:30,2:00。日期和時間格式
public void doWork() {
runOnUiThread(new Runnable() {
public void run() {
try{
TextView txtCurrentTime= (TextView)findViewById(R.id.lbltime);
Date dt = new Date();
int hours = dt.getHours();
int minutes = dt.getMinutes();
int seconds = dt.getSeconds();
String curTime = hours + ":"+minute + ":"+ seconds;
txtCurrentTime.setText(curTime);
}catch (Exception e) {}
}
});
}
class CountDownRunner implements Runnable{
// @Override
public void run() {
while(!Thread.currentThread().isInterrupted()){
try {
doWork();
Thread.sleep(1000);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}catch(Exception e){
}
}
}
}
我已經得到了這段代碼所以我可以用它來獲得當前小時和分鐘,以hh:mm格式。如何進一步處理?
是完美的。我正在尋找的那個。 thankx – samir 2012-03-21 10:28:32