这是我的约会对象.
Fri, 25 Sep 2015 12:01:16 +0000
输出应该如下所示.
2015-09-25 12:01:16
这不起作用.
SimpleDateFormat sdf = new SimpleDateFormat("E, d M y H:m:s X");
Run Code Online (Sandbox Code Playgroud)
我需要将它转换为mysql日期.
我有这个错误
Exception in thread "main"
java.text.ParseException:Unparseable date: "25 Sep 2015 12:01:16"
at java.text.DateFormat.parse(DateFormat.java:366)
at Main.main(Main.java:27)
Run Code Online (Sandbox Code Playgroud)
您的格式已关闭,您需要三个M(s)来获取缩减的月份名称(使用一个给出数字值).就像是,
String str = "Fri, 25 Sep 2015 12:01:16 +0000";
SimpleDateFormat sdf = new SimpleDateFormat("E, d MMM y H:m:s X");
try {
System.out.println(sdf.parse(str));
} catch (ParseException e) {
e.printStackTrace();
}
Run Code Online (Sandbox Code Playgroud)
我得到一个有效的Date.至于上面的调试,验证格式的快速而肮脏的方法就像
System.out.println(sdf.format(new Date())); // <-- check your format pattern
Run Code Online (Sandbox Code Playgroud)