2015-04-03 33 views
1

我已經構建了一個以兩種不同方式告訴時間的錶盤。手錶面具有當前時區的12小時格式和GMT格式的24小時格式。默認情況下,錶盤只顯示當前時區,這意味着我們的GMT時針實際上只是以24小時格式指示當前時區中的時間。如何讓手錶同時顯示多個時區?如何在Android Wear錶盤上顯示多個時區

回答

0

您可以創建不同的時區2個日曆對象,然後使用這個對象:

Calendar germanyTime = new GregorianCalendar(TimeZone.getDefault());//your timezone 
Calendar germanyTime = new GregorianCalendar(TimeZone.getTimeZone("GMT+0")); 
+0

感謝您指點我在正確的方向。我的代碼應該在哪裏應用? – skeete 2015-04-06 21:48:13

+0

這段代碼演示的主要思想,你可以容納2個獨立的日曆對象,並從不同的時區獲取時間 – x90 2015-04-07 21:11:21

+0

我明白,但我沒有主程序員,所以它對我來說有點陌生。大聲笑 – skeete 2015-04-07 22:01:09

0

我會給你我是如何設法自動獲得系統的時間格式的例子:

// variables 
boolean is24Hour = false; 
DateFormat df; 
Calendar cal; 

// get time format 
is24Hour = df.is24HourFormat(context); 

... 

@Override 
    public void onDraw(Canvas canvas, Rect bounds) { 
    // always get a new instance in your onDraw() 
     cal = Calendar.getInstance(); 

    // get the hours 
     if (is24Hour) { 
      format = new SimpleDateFormat("H"); 
      return Integer.valueOf(format.format(cal.getTime())); 
     } else { 
      format = new SimpleDateFormat("h"); 
      return (Integer.valueOf(format.format(cal.getTime())); 
     } 
    } 
相關問題