java parseexception :Unparseable date: "7-Jun-2013"
首先是appointmentclass,主要就是转换个日期importjava.text.SimpleDateFormat;importjava.util.Date;im...
首先是appointment class,主要就是转换个日期
import java.text.SimpleDateFormat;
import java.util.Date;
import java.text.ParseException;
public class Appointment {
private Date date;
private String description;
private SimpleDateFormat formatter = new SimpleDateFormat("dd-MMM-yyyy");
public Appointment(String aDate, String aDescription) throws ParseException{
date=formatter.parse(aDate);
description=aDescription;
}
//. . .
public String toString() {
String tmp = "Appointment [date="
+ formatter.format(date)
+ ", description=" + description + "] ";
return tmp;
}
}
然后创建了一个testprogram来测试…问题出现了:Unparseable date: "7-Jun-2013"
import java.text.ParseException;
public class AppointmentBook{
public static void main(String args[]){
String dateInString ="7-Jun-2013";
try{
Appointment a=new Appointment(dateInString,"asd");
System.out.println(a.toString());
}
catch(ParseException e){
System.out.println(e.getMessage());
}
}
}
检查不出错误,请大神指点,另外,有个很奇怪的现象就是我用dd/MM/yyyy(当然dateinstring也改成7/3/2013)的话就没报错。是不是语言环境设置问题?我是中文 展开
import java.text.SimpleDateFormat;
import java.util.Date;
import java.text.ParseException;
public class Appointment {
private Date date;
private String description;
private SimpleDateFormat formatter = new SimpleDateFormat("dd-MMM-yyyy");
public Appointment(String aDate, String aDescription) throws ParseException{
date=formatter.parse(aDate);
description=aDescription;
}
//. . .
public String toString() {
String tmp = "Appointment [date="
+ formatter.format(date)
+ ", description=" + description + "] ";
return tmp;
}
}
然后创建了一个testprogram来测试…问题出现了:Unparseable date: "7-Jun-2013"
import java.text.ParseException;
public class AppointmentBook{
public static void main(String args[]){
String dateInString ="7-Jun-2013";
try{
Appointment a=new Appointment(dateInString,"asd");
System.out.println(a.toString());
}
catch(ParseException e){
System.out.println(e.getMessage());
}
}
}
检查不出错误,请大神指点,另外,有个很奇怪的现象就是我用dd/MM/yyyy(当然dateinstring也改成7/3/2013)的话就没报错。是不是语言环境设置问题?我是中文 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询