如何比较JTable中的当前日期和给定日期?

问题描述:

美好的一天. 我还有另一个与Jtable有关的问题. 如果列(过期)中的日期超过或等于当前日期,我想更改表的行颜色.

Good Day. I've got another problem related to Jtable. I want to change the row color of a table if the date inside column (expiry) exceeds or is equal to the current date.

我尝试了这段代码,但出现错误:java.lang.NumberFormatException:输入字符串:"2012-03-15"

I tried this code but i get an error: java.lang.NumberFormatException: For input string: "2012-03-15"

SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");     
Calendar cal  = Calendar.getInstance();           
String expDateString = sdf.format(cal.getTime());
System.out.println(expDateString);
Double date = Double.parseDouble(expDateString);
Double val = Double.parseDouble(tableSummary.getModel().getValueAt(row, 6).toString());

for(int i=0; i<=tableSummary.getRowCount()-1; i++){
   if(val >= date){
        renderer.setBackground(red);
   }
}

谢谢!

这是一个新代码:

 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");     
 Calendar cal  = Calendar.getInstance();           
 String expDateString = sdf.format(cal.getTime());

 Date today = new Date(expDateString);
               System.out.println("ang churva is " + today);
 Date given = new Date(tableSummary.getModel().getValueAt(row, 6).toString());

 for(int i=0; i<=tableSummary.getRowCount()-1; i++){
      if(today.compareTo(given)>=0){
            renderer.setBackground(red);
       }
 }

但是我得到了这个异常:今天的Date的java.lang.IllegalArgumentException = new Date(expDateString);

but i get this exception: java.lang.IllegalArgumentException at Date today = new Date(expDateString);

使用代码

DATEDIFF('d',NOW(),exdate)

您的结果集查询中的

.它将返回差额.对其进行更改以符合您的需求.

in your resultset query. It will return the difference. Alter it possibly to match your needs.