in Java, how to parse a date string that contains a letter that does not represent a pattern?
\"2007-11-02T14:46:03+01:00\"
String date =\"2007-11-0
You can try
String format = "yyyy-MM-dd'T'HH:mm:ssz";
Reference : from Javadoc
Text can be quoted using single quotes (') to avoid interpretation.
If you don't care about the time zone, you can use this method.
public static Date convertToDate(String strDate) throws ParseException {
Date date = null;
if (strDate != null) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
date = sdf.parse(strDate);
}
return date;
}
I don't know if it's still useful for you, but I encounter with the same problem now, and after a little I come up with this.
String testDate = "2007-11-02T14:46:03+01:00";
DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssz");
Date date = formatter.parse(testDate);
System.out.println(date);
You can try similar to the above
You can use following link for reference
The time you're trying to parse appears to be in ISO 8601 format. SimpleDateFormat
unfortunately doesn't support all the same timezone specifiers as ISO 8601. If you want to be able to properly handle all the forms specified in the ISO, the best thing to do is use Joda time.
This example is straight out of the user guide:
DateTime dt = new DateTime("2004-12-13T21:39:45.618-08:00");