Vote count:
0
response from jsp is coming in this format: "mm/dd/yyyy hh:mm", i want to convert to db format "yyyy-mm-dd hh:mm:ss"
i tried this code :-
public java.sql.Date getdateFormat(String datestring)throws ParseException{
String datestr="";
try{java.util.Date date=new SimpleDateFormat("mm/dd/yyyy hh:mm a",
Locale.ENGLISH).parse(datestring);
atestr=new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").format(date);
}catch(Exception e){
e.printStackTrace();
}
return getDateFromString(datestr);
}
public java.sql.Date getDateFromString(String string)
{
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
java.util.Date finalDate = null;
try {
finalDate = sdf.parse(string);
}catch (Exception e) {
e.printStackTrace();
}
return new java.sql.Date(finalDate.getTime());
}
asked 31 secs ago
Aucun commentaire:
Enregistrer un commentaire