Here you can find the source of convertISO8610ToCalendar(String iso8601string)
Parameter | Description |
---|---|
iso8601string | ISO8601 UTC string |
public static Calendar convertISO8610ToCalendar(String iso8601string)
//package com.java2s; //License from project: Open Source License import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.*; public class Main { /**//w w w . j a v a 2 s . co m * Convert an ISO8601 UTC string to a Calendar object. * @param iso8601string ISO8601 UTC string * @return Calendar object */ public static Calendar convertISO8610ToCalendar(String iso8601string) { Calendar calendar = GregorianCalendar.getInstance(); String s = iso8601string.replace("Z", "+00:00"); try { s = s.substring(0, 22) + s.substring(23); // to get rid of the ":" SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ"); formatter.setTimeZone(TimeZone.getTimeZone("UTC")); Date date = formatter.parse(s); calendar.setTime(date); } catch (IndexOutOfBoundsException e) { //e.printStackTrace(); } catch (ParseException e) { //e.printStackTrace(); } finally { return calendar; } } }