Formats for date and dateTime in JSON payloads
- Last Updated: June 26, 2023
- 2 minute read
- Corticon.js
- Documentation
Date and DateTime values in a Corticon.js payload must conform to the ISO 8601 standard, or as the number of milliseconds since the epoch. The Corticon.js runtime does all its computation using UTC as the time reference. At runtime, Corticon.js always returns date or dateTime formatted as ISO 8601 regardless of the input format you used.
Date and dateTime values that are passed into Corticon.js at runtime must conform to the ISO 8601 standard. If a non-ISO 8601 date or dateTime is passed inside the payload to the Decision Service, the JavaScript runtime will fail to parse it, and the execution will terminate.
There are many different formats included in the ISO 8601 standard, not limited to, “Date”, “Date and Time”, and “Date and Time with Time Zone offset”. When you use a full Date and Time with Time Zone offset value inside your payload, you remove any potential misinterpretation of the dateTime value in the JavaScript runtime, which may influence how certain Rules will fire. If Time is missing, it defaults to midnight (00:00:00). If Time Zone is missing, it defaults to the Time Zone of the machine running the JavaScript runtime.
If you wanted to pass the date time (UTC) “Thursday, July 30, 2020 6:00:00 PM” into a decision service as a JSON payload, you could format it as:
- 2020-07-30T18:00:00.000Z—This represents the dateTime as ISO 8601 directly with the UTC reference (that is, with no time zone specified).
- 2020-07-30T14:00:00.000-04—This represents the dateTime as ISO 8601 with a time zone (notice instead of 18 hour, it is 14). This format is accepted as input but will not return the results in the same notation.
- 1596132000000—This format represents the dateTime as the number of milliseconds since the epoch, 1/1/1970.
