问题
Im new in struts2 , and created a small web application, i want to a post is timer and i choose jquery datetimpicker, after user choose time and date ,it will dislay in time and date that user chosen.
i use this jquery
http://www.javascriptkit.com/script/script2/tengcalendar.shtml
my problem is, in action of struts2 it can get date but time it return is 00:00:00
exactly the result is :
Tue Nov 20 00:00:00 ICT 2012
and my action class is:
public class Foo extends ActionSupport{
private Date fooDate;
//getter - setter;
}
and my form is:
//form ....
<s:textfield name="fooDate" id="dateReleased"
cssClass="mws-textinput" cssStyle="width:80%" />
<a href="javascript:NewCal('dateReleased','ddmmyyyy',true,12)">
<img src="js/cal.gif" width="16" height="16"
border="0" alt="Pick a date">
</a>
when i choose 2012-11-20 5:40:10PM
and in action class i just got
Tue Nov 20 00:00:00 ICT 2012
But i want
Tue Nov 20 5:40:10 PM ICT 2012
how can i do it?
回答1:
By default Struts2 uses "short format for the Locale associated with the current request" to parse dates. Use String for you fooDate and convert to date in methods where you need it or create type converter for Date http://struts.apache.org/2.x/docs/type-conversion.html.
回答2:
And that Calendar is not jQuery, just javascript, pretty ugly.
This is the real jQuery DatePicker: http://jqueryui.com/datepicker/
And there are currently a couple of customization of it to add the Time too:
http://trentrichardson.com/examples/timepicker/
http://umcdatetimepicker.codeplex.com/
or the standalone TimePicker: http://haineault.com/media/jquery/ui-timepickr/page/
Eye-Candy for the win.
来源:https://stackoverflow.com/questions/13470143/struts2-date-can-not-get-time-by-jquery-datetimepicker