XPages: display DateTime value using browser's locale

只谈情不闲聊 提交于 2019-12-25 02:32:46

问题


I've some computed text on an XPage bound to a document data source, and trying display the date component of a Notes DateTime field using SSJS.

I've always used the doc.getItemValueDateTimeArray method, however it seems to be tied to the server's locale (if I change the browser's language from UK to US, the date format's still dd/mm/yyyy).

How do I output the date in a format that honours the browser's language setting?


回答1:


Try adding a converter (that displays the data source value directly without using doc.getItemValueDateTimeArray):

<xp:text escape="true" id="computedField1" value="#{document1.dateField}">
    <xp:this.converter>
        <xp:convertDateTime type="date"></xp:convertDateTime>
    </xp:this.converter>
</xp:text>



回答2:


The getItemValueDateTimeArray() method returns a list (java.util.Vector to be exact) of NotesDateTime values. The XPages runtime will only honour the browser's language setting if you pass it a java.util.Date object.

There are a couple of methods you can use.

Bind the computed field directly to the document's field (recommended approach):

<xp:text
   escape="true"
   id="computedField1"
   value="#{document1.$revisions}">
</xp:text>

Use the toJavaDate() method of the NotesDateTime class to return a java.util.Date:

<xp:text
   escape="true"
   id="computedField1"
   value="#{javascript:var doc = document1.getDocument();
     var dt:NotesDateTime = doc.getItemValueDateTimeArray('$revisions').get(0);
     return dt.toJavaDate();}">
</xp:text>

Once you have a java.util.Date object you can also add a converter to the field to format the date, but the samples above will already listen to the browser's locale.



来源:https://stackoverflow.com/questions/22841462/xpages-display-datetime-value-using-browsers-locale

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!