mercredi 1 juillet 2015

Multiple Dateformat

i am task to change the dateformat according to the user's language. Currently the website runs in Chinese and English, However i am unable to change the format of the mask according to the user's language.

  <h:outputText styleClass="outputText"
                        id="index_output_todate" value="#{msg.index_output_todate}">
                    </h:outputText>
                    <p:calendar
                        value="#{pc_Index.w_message.am_todate_filter}"
                        id="index_input_todate" styleClass="calendar" maxlength="10"
                        pattern="#{pc_Index.dateDisplayFormat}" onfocus="$(this).mask('9999年99月99日');">
                        <p:watermark for="index_input_todate" value="#{pc_Index.watermarkDateDisplayFormat}" />
                        <f:convertDateTime pattern="#{pc_Index.dateDisplayFormat}" />
                    </p:calendar>

I need the date format of the mask to be 9999年99月99日 when the user login as a zh_CN user or a date format of DD/MM/YYYY for en_UK user. Is there a way to do this?

I had already set the locale

 public String getDateDisplayFormat() {  

    String locale = getUserLocale();
    String DATEFORMAT_UK = "dd/MM/yyyy";
    String DATEFORMAT_US = "mm/dd/yyyy";
    String DATEFORMAT_CN = "yyyy年MM月dd日";
    String _s = DATEFORMAT_UK;
    if(!isEmptyNull(locale) && locale.equals("en_US")) {
        _s = DATEFORMAT_US;
    }
    else if(!isEmptyNull(locale) && locale.equals("zh_CN")) {
        _s = DATEFORMAT_CN;
    }
    return _s;
}

Aucun commentaire:

Enregistrer un commentaire