Customize date formats with Moment.js

Introduction

This article introduces how to use the Moment.js library, listed on the Kintone CDN. It can be used to convert dates into different formats, such "xx days ago".


A GIF of moment.js being integrated with a Kintone App to display custom moment date formats in the Record List view.

What is Moment.js?

Moment.js is a JavaScript library used to alter, validate, calculate and display date and time data. The source code and documents can be found on the Moment.js website.

Import Moment.js for the Kintone App

In the JavaScript and CSS Customization settings of the Kintone App, add a link to the Moment.js library listed in the Kintone CDN.

A screenshot of the Kintone App settings where a link to the moment.js library is specified.

For more information on how to use the libraries in the CDN, refer to the How to Use the CDN article.

Use Moment.js with Kintone

Once the Moment.js library has been imported, it is possible to call the Moment.js methods within Kintone. Here are some examples:

Moment.js makes manipulating date formats very easy.
For more information on how to use the Moment.js library, refer to Moment.js documentation.

Moment.js sample on Kintone

Upload the following code to the JavaScript and CSS Settings of the App, after the Moment.js CDN link.

A screenshot of the Kintone App settings where a new JavaScript file has been uploaded together with the link to the moment.js library.

Click Save and Update App to view the changes in the record list.

This code specifies a field code of a Datetime field in the App, and uses Moment.js to convert the date into a new format. The new format is placed in the record list instead of the original date format.

 

Finally

Formatting date and time by using only standard JavaScript can be a troublesome task, but using Moment.js can help save a lot of time and effort. Additionally, the Moment Timezone library allows date and time to be changed to a different timezone by JavaScript. For any trouble handling Moment.js on Kintone, please post an issue in the Kintone Developer Program community.

Was this article helpful?
0 out of 0 found this helpful
Do you have any questions or issues related to this article?
Please share your views with us in the Community forums!