谁能告诉我为什么我在以下代码中得到 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/