Java.text.ParseException: Opaque date: convert string mm / dd / yyyy to date
4 answers
There are several potential problems here:
- You don't specify the format
- You do not specify the locale
- You do not specify a time zone
- You are trying to cast the return value (which will be a reference
java.util.Date
) tojava.sql.Date
- this will throw an error
You need 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());
+12
source to share
I have the following exception:
java.text.ParseException: Continuous 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);
0
source to share
You mixed m
and m
.
m
indicates minutes and m
within a 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));
0
source to share