我从 Joynet 云 api 服务器获取日期格式:
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);