具有区域设置的xhtml Java日历

时间:2019-02-22 09:35:55

标签: java calendar locale

当我选择某个日期时,我正在使用日历图标,然后它以dd / MM / YYYY的形式显示,并以语言环境格式保存到db中。

现在我正在尝试编辑该页面页面,因此日期以区域格式填充,而不是此格式的dd / MM / YYYY。

所以我再次保存,然后给出错误“无效时间戳记”。如果formate与相应的语言环境不匹配,则由用户定义msg。

所以您能解释一下日历如何选择各自的语言环境


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 个答案:

没有答案