我想通过减去然后将毫秒除以天来比较两个日期,但是这每次返回-5479。我的语法有什么问题吗?我不知道为什么会发生这种情况。日期比较不起作用
if (task_date_view != null) {
Date current_date = new Date();
String myFormat = "MM/dd/yy";
DateFormat dateFormat = new SimpleDateFormat(myFormat);
Date temp_date;
try {
temp_date = dateFormat.parse(list_task.getDate());
long difference = temp_date.getTime() - current_date.getTime();
long diffDays = difference/(24 * 60 * 60 * 1000);
String date_string = Long.toString(diffDays);
task_date_view.setText(date_string + " days left.");
} catch (ParseException e) {
task_date_view.setText("No days left.");
}
}
可能的重复[如何在Java中比较日期?](http://stackoverflow.com/questions/2592501/how-to-compare-dates-in-java) – Rao
您的输入和预期输出是什么? – shmosel
*将毫秒分为几小时* - 您的意思是几天? – shmosel