I am aware of the format using (yyyy-MM-dd) but the inputted date must be in yyyy/MM/dd and i am having trouble formatting it cause java wont read the format yyyy/MM/dd how to do this cause in model its in date format and i cannot set it when im returning string so return value must also be in date??
My request parameter from JSP
String HireDate = request.getParameter("hireDate");
emp.setDoh(DateUtil.StringToDate(HireDate));
MY JQuery
$( function() {
$( "#hireDate" ).datepicker({ dateFormat: "yy/mm/dd" }).val();
});
My Model
private Date doh;
public Date getDoh() {
return doh;
}
public void setDoh(Date doh) {
this.doh = doh;
}
DateUtil Class
public static Date StringToDate(String date) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd", Locale.ENGLISH);
java.util.Date date1 = null;
try {
date1 = sdf.parse(date);
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Date sqlDate = new Date(date1.getTime());
return sqlDate;
}
public static String DateToString(java.util.Date date) {
String convertedDate = "";
if(date != null){
Format formatter = new SimpleDateFormat("yyyy/MM/dd");
convertedDate = formatter.format(date);
}
return convertedDate;
}
}
I would like to make a static boolean function in another class which i will call to know if its a valid date whenever im using format yyyy/MM/dd in parsing it always returns the whole date including CST year etc,any suggestions??