有人可以告诉我为什么我得到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");
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句