日期:2014-05-18  浏览次数:20996 次

JSP中日期相减的问题
各位大侠,我想请问如何将两个日期相减呢?
<%
String inureTime="20070101000000";
java.text.SimpleDateFormat formatter = new java.text.SimpleDateFormat("yyyyMMddHHmmss"); 
java.util.Date currentTime = new java.util.Date();//得到当前系统时间 
String str_date1 = formatter.format(currentTime);

>%
怎么求当前时间str_date1 和inureTime之间相差的天数呢?我该怎么写呢?谢谢各位了!

------解决方案--------------------
HTML code

public boolean getQuot(String time1) {
    boolean bool = false;
    long quot = 0;
    SimpleDateFormat ft = new SimpleDateFormat("yyyy-MM-dd");
    try {
        Date date1 = ft.parse(time1);
        Date date2 = new Date();
        if(date1.getTime()<date2.getTime()){
        quot =  date2.getTime()- date1.getTime();
        quot = quot / 1000 / 60 / 60 / 24;
        if(quot>0){
            bool = false;
        }else{
            bool = true;
        }
        }else{
            bool = false;
        }
    } catch (ParseException e) {
        e.printStackTrace();
    }
    return bool;
}

------解决方案--------------------
如果是要得到相差的天数只要要将一楼的quot = date2.getTime()- date1.getTime();
改成quot = parseInt(date2.getTime()- date1.getTime());
后面的不要了
------解决方案--------------------
探讨
HTML code
public boolean getQuot(String time1) {
boolean bool = false;
long quot = 0;
SimpleDateFormat ft = new SimpleDateFormat("yyyy-MM-dd");
try {
Date date1 = ft.parse(time1);
Date date2 = new Date();
if(date1.getTime()<date2.getTime()){
quot = date2.getTime()- date1.getTime();
quot = quot / 1000 / 60 / 60 / 24;
if(q…