Date date1 = null,date2=null;
SimpleDateFormat format = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
try {
date1= format.parse(jLabel2.getText());
} catch (ParseException ex) {
Logger.getLogger(Settlements.class.getName()).log(Level.SEVERE, null, ex);
}
try {
date2= format.parse(jLabel3.getText());
} catch (ParseException ex) {
Logger.getLogger(Settlements.class.getName()).log(Level.SEVERE, null, ex);
}
long subDateValue = date2.getTime()-date1.getTime();
long subValueinDays = subDateValue/(24 * 60 * 60 * 1000);
System.out.println(subValueinDays + "Days");
//我得到了一个异常:java.text.ParseException:不可解析日期: “2014年10月10日” jLabel1的= 10 /二千零十四分之十 jlabel2 = 2014年11月10日如何。减去两个日期(在JLabel的集合)
的可能重复【如何分析日期?] (http://stackoverflow.com/questions/999172/how-to-parse-a-date) – 2014-09-27 17:17:57
可能重复此[上一个问题](http://stackoverflow.com/q/26064109/230513)。你尝试过'LocalDate'和'Period'吗? – trashgod 2014-09-27 17:52:41