带有区域设置的xhtml java日历
当我选择某个日期时,我使用了日历图标,然后它显示在(就像dd/MM/YYYY)中,并以区域设置格式将其保存到数据库中
现在我正在尝试编辑该页面,以便使用区域设置格式填充日期,而不是使用dd/MM/YYYY这种格式
所以我再次保存,然后给出错误“无效时间戳”。如果formate与相应的语言环境不匹配,则为用户定义消息
那么你能解释一下日历是如何选择各自的语言环境的吗
xhtml页面
<ips:calendar id="EditLPNHeaderInbound_ExpirationDate_calendar" showTime="false" converter="ips.converter.Timestamp"
value="#{lpnBackingBean.IPSDetailData.dataObject.expirationDateString}" size="12" showfullyear="true">
</ips:calendar>
java代码
public String getExpirationDateString()
{
if (lpnObject != null && lpnObject.getExpirationDate() != null) {
return DTTMFormat.timestampToStringWithShortTZName(lpnObject.getExpirationDate(),
getLocale(), getContextTimeZone());
String dateStr =
DateFormat formatter = DateFormat.getDateInstance(DateFormat.LONG, WMMisc.getLocale());
Date date = null;
try {
date = (Date)formatter.parse(dateStr);
} catch (ParseException e) {
e.printStackTrace();
}
}
Calendar cal = Calendar.getInstance();
cal.setTime(date);
String formatedDate = (cal.get(Calendar.MONTH) + 1) + "/" + cal.get(Calendar.DATE) + "/" + cal.get(Calendar.YEAR);
return formatedDate;
}
}
共 (0) 个答案