Reputation: 159
I have an odd issue with date format. Like, i'm using jquery date picker which is set to format dd/mm/yy. so, when i'm filling the field with 01/09/2015, it should mean the date is 1st sep, 2015. But, I see when I receive the filed in controller as a Date, the actual date looks like Fri Jan 09 00:00:00 IST 2015. This is not what I want, I want the date as 1st Sep, 2015. Please help me on what i'm missing. Below is the code snippet for your reference- jsp
function() {
$(".datepicker").datepicker({
dateFormat: "dd/mm/yy",
maxDate : 0,
changeMonth : true,//this option for allowing user to select month
changeYear : true, //this option for allowing user to select from year range
showOn : "button",
buttonImage : "<c:url value="resources/images/calendar.gif"/>",
buttonImageOnly : true,
buttonText : "Select date",
showOtherMonths : true,
selectOtherMonths : true
})
});
<form:form method="post" id="inbound_form" modelAttribute="formObject" action="submit" onsubmit="return validateInboundAdd()" >
<form:input class="datepicker required" style="height:14px"
id="dateReceived" size="10" maxlength="10" type="text" readonly="readonly" value="${dateReceivedContinue}"
path="dateReceived" onfocus="inputFocus(this)" onblur="inputBlur(this)"/>
Controller
@RequestMapping(value = "/submit" , method = RequestMethod.POST , params="Save ")
public String submit(@ModelAttribute("formObject") modelObject modelObject,
System.out.println("received date -"+modelObject.getDate_received()); // This is giving me the mm/dd/yyyy output, which I want as dd/mm/yyyy. This is getter of the date field 'dateReceived'
Upvotes: 0
Views: 1253
Reputation: 748
Define the pattern over the date_received field in model formObject, so that spring can handle the conversion properly
@DateTimeFormat(pattern="dd/MM/yyyy")
Hope it will work!!!
Upvotes: 1