when i convert my string object in mm/dd/yyyy
format to Date
it gives me
java.text.ParseException: Unparseable date: \"09/17/2014
I have the following exception:
java.text.ParseException: Unparseable date
System.out.println("inside the XMLGregorianCalendar");
sb = (String) map.get(fieldname);
System.out.println("THis is XMLGReogoriaaaaan calendar"+ sb);
DateFormat df = new SimpleDateFormat("yyyy-MM-dd", Locale.US);
Date journeyDate = new java.sql.Date(df.parse(sb).getTime());
System.out.println("this"+journeyDate);
There are several potential problems here:
java.util.Date
reference) to a java.sql.Date
- that would failYou want something like:
DateFormat df = new SimpleDateFormat("MM/dd/yyyy", Locale.US);
df.setTimeZone(...); // Whatever time zone you want to use
Date journeyDate = new java.sql.Date(df.parse(text).getTime());
DateFormat df = new SimpleDateFormat("MM/dd/yyyy",Locale.ENGLISH);
Date journeyDate = df.parse(date); // gives you java.util.Date
If you want java.sql.Date then
java.sql.Date sqlDate = new java.sql.Date(journeyDate.getTime());
You have mixed m
and M
.
m
stands for minute and M
for month.
Below is an example of a working format.
SimpleDateFormat formatter = new SimpleDateFormat("MM/dd/yyyy");
String dateInString = "07/06/2013";
Date date = formatter.parse(dateInString);
System.out.println(formatter.format(date));