在jdk1.7以上时,可以这样很好的解决了ISO 8601时间的问题。
TimeZone tz = TimeZone.getTimeZone("UTC");
DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssX");
df.setTimeZone(tz);
String nowAsISO = df.format(new Date());
System.out.println(nowAsISO);
DateFormat df1 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssX");
//nowAsISO = "2013-05-31T00:00:00Z";
Date finalResult = df1.parse("2016-07-28T08:17:52+00:00");
System.out.println(finalResult);
参考资料:
http://stackoverflow.com/questions/2201925/converting-iso-8601-compliant-string-to-java-util-date
http://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html
TimeZone tz = TimeZone.getTimeZone("UTC");
DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssX");
df.setTimeZone(tz);
String nowAsISO = df.format(new Date());
System.out.println(nowAsISO);
DateFormat df1 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssX");
//nowAsISO = "2013-05-31T00:00:00Z";
Date finalResult = df1.parse("2016-07-28T08:17:52+00:00");
System.out.println(finalResult);
参考资料:
http://stackoverflow.com/questions/2201925/converting-iso-8601-compliant-string-to-java-util-date
http://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html