Here you can find the source of getDateFromISO8601(String dateString)
Date
object from the dateString
Parameter | Description |
---|---|
dateString | The date as a string in ISO-8601 format |
Date
object.
public static Date getDateFromISO8601(String dateString)
//package com.java2s; //License from project: Open Source License import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; import java.util.TimeZone; public class Main { /**/*from w w w.j a v a 2 s . co m*/ * Gets a <code>Date</code> object from the <code>dateString</code> * @param dateString The date as a string in ISO-8601 format * @return a Java <code>Date</code> object. */ public static Date getDateFromISO8601(String dateString) { String tz = "-08:00"; if (dateString.endsWith(":00")) { tz = dateString.substring(dateString.length() - 6); //System.out.println( "debug: tz = " + tz ); } String dateNoTimeZone = dateString.substring(0, dateString.length() - 6); //System.out.println( "debug: dateNoTimeZone = " + dateNoTimeZone ); SimpleDateFormat format = new SimpleDateFormat( "yyyy-MM-dd'T'HH:mm:ss"); TimeZone timezone = TimeZone.getTimeZone("GMT" + tz); Calendar cal = Calendar.getInstance(timezone); format.setCalendar(cal); Date date = null; try { date = format.parse(dateNoTimeZone); } catch (ParseException ex) { } return date; } }