Advanced Date and Time Handling
If the date and time system variables do not meet your needs, you can use our simple REST API wrapper for the popular momentjs library.
Use this API as part of a workflow
Create an API call, extract the result and add it to a workflow with your API to take advantage of this functionality.
API syntax
The API provides a simple JSON interface, using GET requests. The momentjs library lets you chain operations together. The key documentation for the functions are available from http://momentjs.com/docs/#/manipulating/ and http://momentjs.com/docs/#/displaying/.
Understand the URL format
The underlying node library is exposed by separating each call by a
/
in the path of the URL. Variables passed to the functions are separated by a~
.
Simple example
The simplest call is https://momentjs.api.expert/
, which returns {"result":"2018-07-16T18:53:09.563Z"}
, i.e. the current time.
Getting the date for next week
A more practical example would be calling the equivalent of
moment.utc().add(7, ‘days’).format()
This is achieved by calling:
https://momentjs.api.expert/utc/add~7~days/format/
which returns: {"result":"2018-07-23T19:08:52Z"}
.
Alternatively, https://momentjs.api.expert/utc/add~7~days/format~llll/
will output the same in a human friendly date format:
{"result":"Mon, Jul 23, 2018 7:09 PM"}
.
Timezones
The timezone module is also installed, so you create more complex calls:
https://momentjs.api.expert/utc~1980-08-20T15:25Z/tz~America%2FLos_Angeles/locale~fr/format~LLLL%20z/
which is the same as calling in Javascript:
moment.utc(“1980-08-20T15:25Z”)
.tz(“America/Los_Angeles”)
.locale(“fr”)
.format(“LLLL z”)
That example parses a UTC date, converts it to the US West Coast timezone and then changes the locale to French so the format outputs the date in French long-friendly format (LLLL
) followed by the timezone (Z
), still in PDT.
The output is:
{"result":"mercredi 20 août 1980 08:25 PDT"}
Note
We have to URL-encode the
/
inAmerica/Los_Angeles
to%2F
as that is part of the URL syntax. The space character in the format string is also converted to%20
.
Updated over 5 years ago