I wolud like to know the difference in milliseconds within two date and time, I use the code below but it add 1 hour more is the TimeZone but on my phone is set to automatically 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;
}