gpt4 book ai didi

java.text.ParseException : Unparseable date: 异常

转载 作者:塔克拉玛干 更新时间:2023-11-03 03:39:11 24 4
gpt4 key购买 nike

谁能告诉我为什么我在以下代码中得到 java.text.ParseException: Unparseable date:

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;


public class Testdate {
public static void main(String args[])
{
String text = "2011-11-19T00:00:00.000-05:00";
DateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
try {
Date parsed = sdf.parse(text.trim());
System.out.println(parsed);
} catch (ParseException e) {
e.printStackTrace();
}
}

}

最佳答案

这是因为您所在时区的冒号。删除它,它将起作用:

String text = "2011-11-19T00:00:00.000-0500";
DateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");

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

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