当我从日期选择器中选择日期格式时,它显示在" dd / MM / yyyy"格式。 将日期传递给java类,它变成" MM / dd / yyyy"。 由于这个原因,我不能超过12天,它显示输入错误。
示例:2014年8月11日在jsp中显示的同一日期 java课程是2014年11月8日星期六00:00:00 IST 2014
答案 0 :(得分:1)
您可以使用DateFormat以所需格式转换日期。
DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
Calendar cal = Calendar.getInstance();
String currDate = dateFormat.format(cal.getTime());
答案 1 :(得分:0)
阅读Date conversion in Struts2,然后按照以下方式在struts.xml中将Locale设置为Struts2:
<constant name="struts.locale" value="it_IT" />
如果您没有构建多语言(i18n)Web应用程序,请使用所需的区域设置而不是it_IT
。
另外考虑使用HTML5本机<input type="date" />
,对不支持该功能的浏览器使用jQuery(对于Modernizr)(对于浏览器):
<script>
// If not native HTML5 support, fallback to jQuery datePicker
$(function(){
if (!Modernizr.inputtypes.date) {
$('input[type=date]').datepicker({
// Consistent format with the HTML5 picker
dateFormat: 'yy-mm-dd'
},
// Localization
$.datepicker.regional['it']
);
}
});
</script>