我目前的写法是
public static String getDate() {
return (new SimpleDateFormat("yyyy-MM-dd",Locale.US)).format(new Date());
}<%long day=(util.getDate()-news.getNews_date())/(24*60*60*1000);
if (day<4) {%><img src='images/new.gif'><%}%>
其中news.getNews_date()的值为2004-08-09 运行提示错误:
operator - cannot be applied to java.lang.String,java.lang.String
public static String getDate() {
return (new SimpleDateFormat("yyyy-MM-dd",Locale.US)).format(new Date());
}<%long day=(util.getDate()-news.getNews_date())/(24*60*60*1000);
if (day<4) {%><img src='images/new.gif'><%}%>
其中news.getNews_date()的值为2004-08-09 运行提示错误:
operator - cannot be applied to java.lang.String,java.lang.String
{
java.util.Date date=new java.text.SimpleDateFormat("yyyy-MM-dd").parse(day);
//因为current有小时,分秒,所以先去掉比较;
java.util.Date current=new java.text.SimpleDateFormat("yyyy-MM-dd).parse(
new java.text.SimpleDateFormat("yyyy-MM-dd").format(new java.util.Date()));
//3天内?
return ((current.getTime()-date.getTime())/1000*60*60*24<=3);
}
operator - cannot be applied to java.lang.String,java.lang.String减号不能用于String
{
java.util.Date date=new java.text.SimpleDateFormat("yyyy-MM-dd").parse(day);
//因为current有小时,分秒,所以先去掉比较;
java.util.Date current=new java.text.SimpleDateFormat("yyyy-MM-dd).parse(
new java.text.SimpleDateFormat("yyyy-MM-dd").format(new java.util.Date()));
//3天内?
return ((current.getTime()-date.getTime())/(1000*60*60*24)<=3);
}
public boolean lessThan3Days(String day) throws java.text.ParseException{
SimpleDateFormat myFormatter = new SimpleDateFormat("yyyy-MM-dd");
java.util.Date date=myFormatter.parse(day);
java.util.Date current=myFormatter.parse(myFormatter.format(new java.util.Date()));
return ((current.getTime()-date.getTime())/(1000*60*60*24)<=3);
}