Toggle menu

moment

A library for parsing, validating, manipulating, and formatting dates.

This library is distributed under the MIT license, its source is www.npmjs.com/package/moment (opens new window). For full documentation see momentjs.com/docs (opens new window).

Executed

Server-side

Details

var moment = require('moment');

Moment.js provides powerful tools for manipulating dates and times. It also has tools to handle local time, UTC and fixed time zone offsets, date formatting. The documentation for moment is exceptionally good, meaning there is little need to reproduce it here. Introductory concepts are found at momentjs.com/guides (opens new window).

Example

Get the date and time in a particular format.

function( params, credentials ) {
    var moment = require('moment');
    var now = moment().format('MMMM Do YYYY, h:mm:ss a');
    return now;
}

{
    "jsonrpc": "2.0",
    "id": 217,
    "result": "September 28th 2016, 11:30:34 am"
}

Timezone

The https://www.npmjs.com/package/moment-timezone has also been included. To use this verion:

var moment = require('moment-timezone');

Last modified on 21 April 2023

Share this page

Facebook icon Twitter icon email icon

Print

print icon