Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/382.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 我怎样才能得到两次约会之间的天数?_Java_Netbeans_Jodatime - Fatal编程技术网

Java 我怎样才能得到两次约会之间的天数?

Java 我怎样才能得到两次约会之间的天数?,java,netbeans,jodatime,Java,Netbeans,Jodatime,如何从两个日期中获取天数一个日期来自数据库,我可以正确地检索它,但如何将其与当前系统日期进行比较?我可以使用settimestamp函数将当前日期存储到数据库中,但无法使用它进行比较我使用了jodatime,但无法通过它 // TODO add your handling code here: JOptionPane.showMessageDialog(null,"Fine test"); try{ conn = Connect.C

如何从两个日期中获取天数一个日期来自数据库,我可以正确地检索它,但如何将其与当前系统日期进行比较?我可以使用settimestamp函数将当前日期存储到数据库中,但无法使用它进行比较我使用了jodatime,但无法通过它

     // TODO add your handling code here:
       JOptionPane.showMessageDialog(null,"Fine test");
        try{
            conn = Connect.ConnectDB();  
            String qw="select bookid,date from borrow";
            //String date1="Select Cast ((JulianDay(ToDate) - JulianDay(FromDate)) As Integer)";
        pst = conn.prepareStatement(qw);
 rs=pst.executeQuery();
 while(rs.next())
 {
     String fine=rs.getString("date");
     //String today=Timestamp(System.currentTimeMillis()
     //String date1="Select Cast ((JulianDay() - JulianDay(fine)) As Integer)";
    //pst = conn.prepareStatement(date1);
    //DateTime ret1=formatter.parseDateTime(df.format(dateobj));
   // DateTime dt = formatter.parseDateTime(fine);
//days = Days.daysBetween(dt,dt).getDays();
    // int n=ChronoUnit.DAYS.between(fine,fine);
      JOptionPane.showMessageDialog(null,"Days are"+fine);
 }
        }
        catch(Exception e)
        {
             JOptionPane.showMessageDialog(null,"Fine error"+e);
        }
    }                                              

    private void formWindowClosed(java.awt.event.WindowEvent evt) {                                  
        // TODO add your handling code here:
        try{
        conn.commit();
        conn.close();
        }
        catch(Exception e)
        {}
    }                                 
从毫秒开始计算怎么样。一天:24*60*60*1000=86400000毫秒

example output:
11/21/2016
11/22/2016
Days between: 2

让我试一试@stokhosTi必须使用当前的系统日期这是不正确的。如果第一个日期是在冬季,第二个日期是在夏季,那么在任何使用夏令时的地区,它都会失败。并非所有的日子都有24小时。最好使用
java.time
或JodaTime,而不是自己尝试实现计算。是的,正确。但是,如果您正在查看带有截断日期的日差,那么结果将是正确的。OP说他们使用的是jodatime。此API有一个明确的函数
Days.between()
,用于满足用户的需求。不需要重新发明轮子
example output:
11/21/2016
11/22/2016
Days between: 2