日期格式的問題,我得到從joynet雲API服務器的日期格式:從Java
2012-11-20T10:26:04+00:00"
不過,我也沒辦法處理的最後一段+00:00,我做了除了+00格式:00
SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
Date date = fmt.parse("2012-11-20T10:26:04");
感謝@Abu
我重寫它移除 「:」,
SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
String input = "2012-11-20T10:25:58+00:00";
String s1 = input.split("T")[0];
String s2 = input.split("T")[1];
String sep = null;
if (s2.contains("+")) {
sep = "+";
}
if (s2.contains("-")) {
sep = "-";
}
String s3 = s2.split("\\" + sep)[0];
String s4 = s2.split("\\" + sep)[1].replace(":", "");
String cleanDate = s1 + "T" + s3 + sep + s4;
Date date = fmt.parse(cleanDate);
System.out.println(date);
而工作的,不是嗎? – sp00m
[JavaDoc](http://docs.oracle.com/javase/6/docs/api/java/text/SimpleDateFormat.html)? – Kai