该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
应该是时间格式不对, 这样可以。
package com.mine.tieba0;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.text.ParseException;
class Appointment {
private Date date;
private String description;
private SimpleDateFormat formatter = new SimpleDateFormat("yyyy.MM.dd-HH.mm.ss");
public Appointment(String aDate, String aDescription) throws ParseException {
this.date = formatter.parse(aDate);
this.description = aDescription;
}
// . . .
public String toString() {
String tmp = "Appointment [date=" + formatter.format(date)
+ ", description=" + description + "] ";
System.out.println(tmp);
return tmp;
}
}
public class Demo3 {
public static void main(String args[]) {
String dateInString = "2001.12.12-08.23.21";
try {
Appointment a = new Appointment(dateInString, "asd");
System.out.println(a.toString());
} catch (ParseException e) {
System.out.println(e.getMessage());
}
}
}