How to read from this input into a java...">

How to read input type = "date" for Date java object?

I have an input

<input type="date" name="date"> 

How to read from this input into a java object of the java.util.Date class?

PS The date date is the field of my Bean, which I read like this:

 @RequestMapping("/updateVacancy") public String updateVacancy(@ModelAttribute("vacancy") Vacancy vacancy){ vacancyService.update(vacancy); return "VacancyDetails"; } 
+7
java spring html html5
source share
2 answers

You can get the date as text and then parse it on java.util.Date

For example, for example

 SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); Date parsed = format.parse(date); 

You should also check that the resulting value matches the desired format.

+4
source share

The specification says:

value = date

A string representing the date. A valid full date as defined in [RFC 3339], with the additional qualification that the component of the year consists of four or more digits representing a number greater than 0.

Example:

1996-12-19

Thus, you will have to analyze the value of the parameter in accordance with this format. On the server side, you get the parameter value in the same way as if the field was an entered type text and its value was dated using the yyyy-MM-dd template.

0
source share

All Articles