I'm trying to figure out a way around Input type=date. I am aware that the input display differs in browsers, to clarify things I'm using Google Chrome for this one. So my simple form goes like this:
<input type="date" name="startingdate" class="form-control" id="startingdate"/>
And my controller goes like this:
public ModelAndView getDate(@FormParam("startingdate") String startingdate) {
System.out.println(startingdate);
}
The format as shown in chrome is in mm/dd/yyyy
which is what I want, but when I get the value from html to my controller in string format it suddenly becomes yyyy-mm-dd
.
As an example when I enter 09/11/2018
, it becomes 2018-11-09
in the controller and upon passing it to my database it becomes 0011-08-18
. Is there any other way to fix the format before my controller gets the date value without changing the date format on my database or parsing using simpledateformat?
I am under the impression that it's simply the format's fault, but if there's something I completely missed I am open to suggestions.
Thanks!
UPDATE: The actual problem was on the backend parsing of the startingdate and it went completely under my nose. Fixed the thing by using:
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
java.util.Date startingdateparsed = format.parse(startdate);
java.sql.Date startdatingparse = new java.sql.Date(startingdateparsed.getTime());
Thank you for your time and insights guys!