我想知道两个日期和时间内以毫秒为单位的差异,我使用下面的代码,但它增加了 1 小时是 TimeZone 但在我的手机上设置为自动时区....:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
tempo_text = (TextView)findViewById(R.id.tempo_textv);
Date data = new Date();
long oggi = data.getTime();
long finish = Delay(12,30, 18, 04, 2012);
new TempoIndietro(finish-oggi,1000).start();
}
public class TempoIndietro extends CountDownTimer{
public TempoIndietro(long millisInFuture, long countDownInterval) {
super(millisInFuture, countDownInterval);
}
@Override
public void onFinish() {
}
@Override
public void onTick(long millisUntilFinished) {
SimpleDateFormat df = new SimpleDateFormat("dd : HH: mm: ss");
df.setTimeZone(TimeZone.getDefault());
String risultato = df.format(new Date(millisUntilFinished)); //arg0 tempo in ms preso dall'onTick
tempo_text.setText(risultato);
};
}
public long Delay(int mHour, int mMinute, int giorno, int mese, int anno){
Calendar cal = Calendar.getInstance();
cal.setTimeZone(TimeZone.getDefault());
cal.set(Calendar.DAY_OF_MONTH, giorno);
cal.set(Calendar.MONTH, mese);
cal.set(Calendar.YEAR, anno);
cal.set(Calendar.HOUR_OF_DAY, mHour);
cal.set(Calendar.MINUTE, mMinute);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0);
long delay = cal.getTimeInMillis();
return delay;
}