I get the date format from a joynet cloud api server:
2012-11-20T10:26:04+00:00"
However, I have no idea to handle the last segment +00:00, I have made the format except for +00:00
SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
Date date = fmt.parse("2012-11-20T10:26:04");
Thanks for @Abu
I rewrite it to remove “:”,
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);
Remove that
:inside the time zone part if you are not using java 7and use this :
SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");See javadoc for SimpleDateFormat in Java 6
And
If you are using Java 7 then directly use this :
SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssX");See javadoc for SimpleDateFormat in Java 7