Parse a empty string into SimpleDateFormat

 ̄綄美尐妖づ 提交于 2020-01-06 09:54:57

问题


So, so far I have this:

static SimpleDateFormat df = new SimpleDateFormat("dd MM yyyy");
jDateChooser8 = new com.toedter.calendar.JDateChooser();

when I parse the right date let's say this one:

jDateChooser8.setDate(df.parse("24 07 1987"));

it's ok, but when I try to parse "" (empty string)

jDateChooser8.setDate(df.parse(""));

I get an exeption:

first line of error is:

java.text.ParseException: Unparseable date: ""

all I want to do is set date to "", how to do it?


回答1:


The javadoc for parse states: "Throws: ParseException - if the beginning of the specified string cannot be parsed."

The string "" cannot be parsed, and thus a ParseException is thrown.




回答2:


i did what i want with seems it worked.

jDateChooser8.cleanup();


来源:https://stackoverflow.com/questions/28541698/parse-a-empty-string-into-simpledateformat

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!