将日期与当前日期进行比较
答
使用的SimpleDateFormat:
如果你的日期是在31/12/2014格式。
String my_date = "31/12/2014"
然后,你需要将其转换成的SimpleDateFormat
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
Date strDate = sdf.parse(my_date);
if (new Date().after(strDate)) {
your_date_is_out_dated = true;
}
else{
your_date_is_outdated = false;
}
或
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
Date strDate = sdf.parse(my_date);
if (System.currentTimeMillis() > strDate.getTime()) {
your_date_is_out_dated = true;
}
else{
your_date_is_outdated = false;
}
+0
sdf.parse(my_date)这个地方强调一个错误:未处理的异常java.text.parseexception ...(( –
+0
)你可以检查你的代码中导入的包。 – ISHIDA
是需要输入你的名字比它需要找到一个例子的时间长的时间在谷歌的日期比较... – alfasin
@alfasin我是新手。然而我在看。我不适合的事实。无法正确理解。 –