I want to convert string "10/7/2015 6:31am"
to Date
in java.
I tried follows code, but failed.
String value = "10/7/2015 6:31am";
SimpleDateFormat sdf = new SimpleDateFormat("M/d/yyyy h:mma");
return sdf.parse(value);
What SimpleDateFormat
should I use, please help me
actually, I made a function as follows in Utils.java:
public static Date getDateValueByFormat(String value,String format) {
SimpleDateFormat sdf = new SimpleDateFormat(format);
try {
return sdf.parse(value);
} catch (ParseException e) {
e.printStackTrace();
return null;
}
}
called this function in others class as follows:
String value = "10/7/2015 6:31am";
Date datetime = Utils.getDateValueByFormat(value, "M/d/yyyy h:mma");
unfortunately, threw excption as follows:
java.text.ParseException: Unparseable date: "10/7/2015 6:31am"
at java.text.DateFormat.parse(DateFormat.java:357)
at com.sapmle.common.util.Utils.getDateValueByFormat(Utils.java:28)
anyone has idea?
PS: I used jdk is 1.7.0_79, has any problem for it?