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 am trying to do it like this :
String date= "09/17/2014";
DateFormat df = new SimpleDateFormat();
Date journeyDate= (java.sql.Date) df.parse(date);
You can try the below format: SimpleDateFormat sdf = new SimpleDateFormat("EE MMM dd HH:mm:ss z yyyy", Locale. ENGLISH);
parseexception: unparseable date” error message, when you try to parse the date string into another desired format. Don't worry it's a very common error message that users generally faced while parsing a date in java using SimpleDateFormat class.
public class ParseException extends Exception. Signals that an error has been reached unexpectedly while parsing. See Also: Exception , Format , FieldPosition , Serialized Form.
Java SimpleDateFormat ExampleString pattern = "MM-dd-yyyy"; SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern); String date = simpleDateFormat. format(new Date()); System. out. println(date);
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());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With