TextView time = findViewById(R.id.timetv);
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
String format1 = df.format(new Date());
time.setText(format1);
try
{
Date startTime = df.parse(format1);
Date endTime = df.parse("2018-01-01 14:10:10");
long diff = startTime.getTime() - endTime.getTime();
long days = diff / (1000 * 60 * 60 * 24);
long hours = (diff-days*(1000 * 60 * 60 * 24))/(1000* 60 * 60);
long minutes = (diff-days*(1000 * 60 * 60 * 24)-hours*(1000* 60 * 60))/(1000* 60);
Log.d("测试diff",diff+"");
Log.d("测试days",days+"");
Log.d("测试hours",hours+"");
}catch (Exception e)
{
}
|