gpt4 book ai didi

java.text.ParseException : Unparseable date: "01-02-2014" 异常

转载 作者:行者123 更新时间:2023-11-29 05:04:27 25 4
gpt4 key购买 nike

我是 servlet 和 jsp 的新手。我正在尝试将日期插入包含更多信息的表中。这是我的代码

	
try{
DateFormat sdf = new SimpleDateFormat("dd/MM/yyyy",Locale.ENGLISH);
Date reg=sdf.parse(request.getParameter("dob"));
}
catch(ParseException e)
{
e.printStackTrace();
}

当我调试并且控制到达这一行时,它会抛出一条错误消息

java.text.ParseException: Unparseable date: "01-02-2014"

谁能帮我解决这个问题

最佳答案

您的格式是 dd/MM/yyyy 但日期是 01-02-2014。使日期格式匹配预期的输入。像这样:

DateFormat sdf = new SimpleDateFormat("dd-MM-yyyy",Locale.ENGLISH);

关于java.text.ParseException : Unparseable date: "01-02-2014" 异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30893790/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com