将一个空字符串解析为SimpleDateFormat [英] Parse a empty string into SimpleDateFormat

查看:489
本文介绍了将一个空字符串解析为SimpleDateFormat的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,到目前为止,我有这个:

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(""));

我得到了豁免:

第一行错误是:

java.text.ParseException: Unparseable date: ""

我只想将日期设置为"",怎么做?

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

推荐答案

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

无法解析字符串"",因此将抛出ParseException.

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

这篇关于将一个空字符串解析为SimpleDateFormat的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆