How to read input type="date" to java object Date?
I have so input
<input type="date" name="date">
How to read from this input to java object of class java.util.Date?
PS Date date is a field of my Bean, which I read so:
@RequestMapping("/updateVacancy")
public String updateVacancy(@ModelAttribute("vacancy") Vacancy vacancy){
vacancyService.update(vacancy);
return "VacancyDetails";
}
You may receive date as text and then parse it to java.util.Date
For example like this
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
Date parsed = format.parse(date);
You should also check that received value corresponds to you desired format.
The specification says:
value = date
A string representing a date. A valid full-date as defined in [RFC 3339], with the additional qualification that the year component is four or more digits representing a number greater than 0.
Example:
1996-12-19
So you'll have to parse the parameter value according to this format. At server-side, you'll get the parameter value exactly as if the field was an input of type text, and its value was a date formatted using the yyyy-MM-dd
pattern.
上一篇: 在CSS calc中使用auto