2017-08-07 79 views
-1

我想:越來越當地時間Android的

TimeZone.getDefault(); 

我想:

Calendar mCalendar = new GregorianCalendar(); 
TimeZone mTimeZone = mCalendar.getTimeZone(); 

我想:

Calendar c = Calendar.getInstance(); 
mTimeZone = c.getTimeZone(); 

不管我怎麼努力...它給了我一個默認爲0GMT。我的應用程序似乎無法得到時區(應改爲-4ET,即美國東部時區)

奇怪的是......我的時鐘顯示我的手機上正確的時間。 「使用自動時區」在我的Android設備的設置中檢查。

那麼,爲什麼我不能在我的應用程序獲得當地時間? Android時鐘如何能夠實現這一點,但不是我?

我在網上查了一下,似乎找不到任何東西。是否至少有一種方法可以與時鐘應用程序同步,並且還可以在我的應用程序上顯示時間?有沒有辦法在我的應用上獲得正確的時間?

+0

的可能的複製[?如何從Android手機時區(https://stackoverflow.com/questions/7672597/how-從android-mobile獲取時區) –

+0

您是在生產發佈的應用程序上進行測試,還是在沙箱中測試應用程序? –

+0

即時將我的應用從Android Studio加載到我的手機進行測試。所以不,它不在應用程序商店,但只在發展模式... –

回答

0

你可以試試:

import java.util.Calendar  
Date currentTime = Calendar.getInstance().getTime(); 

String currentDateTimeString = DateFormat.getDateTimeInstance().format(new Date()); 

// textView is the TextView view that should display it 
textView.setText(currentDateTimeString);