Moment.js - customize date formats


In this article, we introduce how to use the Moment.js library, listed on the Kintone CDN. This library can be used to convert dates into a different format, such as converting it into a format of "xx days ago".


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 their website.

Import Moment.js for you 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.

For more information on how to use the libraries in the CDN, read through this article.

Use Moment.js with Kintone

Once the Moment.js library has been imported, you can 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 their docs.

Moment.js sample on Kintone

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

Click "Save" and "Update App" to view the changes in your Record list.

This code specifies a fieldcode 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.



Formatting date and time by using only standard JavaScript can be a troublesome task, but using Moment.js can help you save a lot of time and effort. Also, if you use a library called Moment Timezone, you can change to a different timezone by JavaScript. If you have any trouble handling Moment.js on Kintone, go ahead to post your 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!