2013-03-27 191 views
0

我有下面的代碼以顯示數字時鐘。本質上它工作正常,但我希望它只顯示24小時格式,因此如果用戶要改變24或12小時之間的設置格式,它不會影響我的應用程序中顯示的時間。Android - 設置數字時鐘只顯示24小時格式的時間

DigitalClock digital_clock_4inches = (DigitalClock)findViewById(R.id.bge_digital_clock_4inches); 
digital_clock_4inches.setTypeface(bge_currentDateandTimeFont_4inches); 

我明白接任這裏http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/1.5_r4/android/widget/DigitalClock.java看到的DigitalClock代碼是一個選項,如果這是西隧確實在代碼中一個變化的情況。

在此先感謝您的幫助。


TIMER:

Timer timer = new Timer(); 
timer.schedule(new TimerTask() { 
    @Override 
    public void run() { 

    } 
},0,1000);//Update text every second 

回答

0

創建使用日曆顯示的時間爲24小時格式和大小的時鐘。

Calendar c = Calendar.getInstance(); 
int seconds = c.get(Calendar.SECOND); 
int min= c.get(Calendar.MINUTE); 
int hour= c.get(Calendar.HOUR); 
if(c.get(Calendar.AM_PM))//if returns pm add 12 to hour 
Textview.append(hour + ":" + min + ":" + seconds); 

使用Timer類每秒更新一次。

+0

嗨Arju,感謝您的幫助。我創建了計時器,但想知道run()方法中的語法...即,我已將上面的代碼調整爲關於剛創建的計時器。 – TokTok123 2013-03-27 14:19:40

相關問題