gpt4 book ai didi

java - 尝试重新格式化日期字符串时出现 "Unparsable date"

转载 作者:行者123 更新时间:2023-12-01 10:42:28 25 4
gpt4 key购买 nike

我想将给定的日期字符串重新格式化为不同的格式:

SimpleDateFormat simpleDateFormat = new SimpleDateFormat("EEEE, MMMM dd, yyyy 'at' KK:mm aa zzzz");   
SimpleDateFormat output = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date d = simpleDateFormat.parse(question.getOccur());
String formattedTime = output.format(d);

我遇到了这个异常:

java.text.ParseException: Unparseable date: "Monday, December 7, 2015 at 12:05:13 PM Eastern Standard Time" (at offset 33)

最佳答案

您错过了日期格式中的秒数。试试这个:

SimpleDateFormat simpleDateFormat = new SimpleDateFormat("EEEE, MMMM dd, yyyy 'at' KK:mm:ss aa zzzz");   
SimpleDateFormat output = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date d = simpleDateFormat.parse(question.getOccur());
String formattedTime = output.format(d);
<小时/>

编辑。对于以下示例:星期四 12/10/2015 01:35 AM,日期格式是这样的:

SimpleDateFormat output = new SimpleDateFormat("EEEE dd/MM/yyyy hh:mm a");

关于java - 尝试重新格式化日期字符串时出现 "Unparsable date",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34370701/

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