私は解決策を思いついたと思います。
データを取得すると、次のようになります。
editPrefs.putLong("fetchTime", System.currentTimeMillis());
アプリケーションが起動し、データが通常要求されると、現在は更新されます。
(注: ページは毎日「午後9時AEDT」-(オーストラリア東部夏時間)に更新され、AEST(オーストラリア東部標準時間)に変更されると思います。 )夏時間が終了したとき。「オーストラリア/ ACT」は、これらのゾーンを通過するタイムゾーンです)
//create calendar date for update threshold based on last fetch time preference
Calendar updateThresh = new GregorianCalendar(TimeZone.getTimeZone("Australia/ACT"));
updateThresh.setTimeInMillis(prefs.getLong("fetchTime", 0));
//increment day if last fetch was >= 9pm of that day
if (updateThresh.get(Calendar.HOUR_OF_DAY) >= 21)
updateThresh.add(Calendar.DAY_OF_MONTH, 1);
//set time to 9:00:00pm
updateThresh.set(Calendar.HOUR_OF_DAY , 21);
updateThresh.set(Calendar.MINUTE , 0);
updateThresh.set(Calendar.SECOND , 0);
//check if current date is before or after
if (updateThresh.before(new GregorianCalendar(TimeZone.getTimeZone("Australia/ACT"))))
{
//update needed (fetch data)
}
else
{
//update not needed (show message)
}
これはうまくいくようです。Australia / ACTに設定されたDateFormatを使用してテストしましたが、機能しているようです...たとえば、フェッチ時間に設定されている別のカレンダーオブジェクトを作成し、次を使用します。
DateFormat df = DateFormat.getDateTimeInstance();
df.setTimeZone(TimeZone.getTimeZone("Australia/ACT"));
testTextField.setText("Last fetch in East AU time: " + df.format(fetchTime.getTimeInMillis()) +
"\nUpdate threshold in East AU time: " + df.format(updateThresh.getTimeInMillis()) );
これにより、携帯電話のタイムゾーン設定を試してみても、一貫して正しい出力が表示されます...このソリューションは機能すると確信しているので、正しい/承認済みとマークします-しかし、誰かがエラーに気付いた場合、またはより良い提案、貢献してください!:)