Reputation: 33
I'm using rest viewJsonService to get data for a dojo datagrid. Time values are shown in Z-Time.
How to get / dispaly the localtime?
Hubert
Upvotes: 2
Views: 247
Reputation: 30960
Add a formatter parameter to your column
<xe:djxDataGridColumn
id="djxDataGridColumn7"
field="created"
formatter="formatTime">
</xe:djxDataGridColumn>
define the formatter code in a client side JavaScript Script Library dojoDataGrid.js
require( [ "dojo/date/locale" ]);
function formatDate(value) {
return value ? dojo.date.locale.format(new Date(value), {
formatLength : "short",
selector : "date"
}) : "";
}
function formatDateTime(value) {
return value ? dojo.date.locale.format(new Date(value), {
formatLength : "short"
}) : "";
}
function formatTime(value) {
return value ? dojo.date.locale.format(new Date(value), {
formatLength : "short",
selector : "time"
}) : "";
}
and embed it as resource in your XPage with
<xp:this.resources>
<xp:script
src="/dojoDataGrid.js"
clientSide="true">
</xp:script>
</xp:this.resources>
You might also have a look at my EntwicklerCamp 2014 presentation at page 14 or Marky Roden's blog Dealing with Dates, and localization in XPages.
Upvotes: 2
Reputation: 1840
Checkout moment.js. It is a super useful javascript library for dealing with anything time/date related.
Upvotes: 0