Passing my salute to every single hard working developer,
and cheers to every struggler out there.
Actually i am here because i got stuck on a very basic problem.
I am building a client-server application, and i am confused about how to compare between two dates extracted from jtable (eventually i've never got across any operations on dates in general).
I've used this code:
public static final String DATE_FORMAT_NOW = "yyyy-MM-dd";
public static String now() {
Calendar cal = Calendar.getInstance();
SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT_NOW);
return sdf.format(cal.getTime());
}
public static void ColorTheCell2(JTable jTable2){
jTable2.getColumn("Date d'expiration").setCellRenderer(
new DefaultTableCellRenderer() {
@Override
public Component getTableCellRendererComponent
(JTable table,Object value,boolean isSelected,boolean hasFocus,int row,int column){
Calendar datetable=Calendar.getInstance();
String date=value.toString();
String day=""+date.substring(8).toString();
String month=""+date.substring(5, 7).toString();
String year=""+date.substring(0,4).toString();
datetable.set(Integer.parseInt(year),Integer.parseInt(month),Integer.parseInt(day));
Calendar curdate=Calendar.getInstance();
String date1=now();
String day1=""+date1.substring(8).toString();
String month1=""+date1.substring(5, 7).toString();
String year1=""+date1.substring(0,4).toString();
curdate.set(Integer.parseInt(year1),Integer.parseInt(month1)+1,Integer.parseInt(day1));
if(datetable.before(curdate)){
setText(value.toString());
setBackground(Color.red);
}
else{
setText(value.toString());
}
return this;
}
});
}
Thank you for your Time. Best regards