Skip to main content

Date/time functions

formatDateTime

Commentary

added in 0.0.17

Generates datetime's for time specified in milliseconds, in the default pattern of yyyy-MM-dd'T'HH:mm:ss.SSSZZ.

Optionally, supply the format with format, which must be a valid JodaTime pattern.


Examples

Default formatting

Omit format for the default formatting.

{
"_gen": "formatDateTime",
"ms": {
"_gen": "now"
}
}
[
"2024-04-25T13:28:47.262-07:00"
]

Specify a format

Set format to control the output string.

{
"_gen": "formatDateTime",
"ms": {
"_gen": "now"
},
"format": "yyyy-MM-dd"
}
[
"2024-04-25"
]

Dates in the past

Because formatDateTime is driven off Unix milliseconds values, you can generate timestamps in the past or future simply by using math.

In this example, timestamps are generated anywhere between 1 and 6 months in the past, whose offsets are represented by 2629746000 and 15778476000 milliseconds respectively.

{
"_gen": "formatDateTime",
"ms": {
"_gen": "math",
"expr": "timestamp - offset",
"names": {
"timestamp": {
"_gen": "now"
},
"offset": {
"_gen": "uniformDistribution",
"bounds": [
2629746000,
15778476000
],
"decimals": 0
}
}
},
"format": "yyyy-MM-dd HH:mm:ss.SSS"
}
[
"2023-12-08 19:22:54.851",
"2024-01-14 11:23:35.009",
"2023-11-11 17:18:51.554",
"2024-01-03 22:15:25.418",
"2023-12-30 19:01:09.743"
]

Specification

JSON schema

{
"type": "object",
"properties": {
"ms": {
"oneOf": [
{
"type": "number"
},
{
"type": "object",
"properties": {
"_gen": {
"type": "string"
}
},
"required": [
"_gen"
]
}
]
},
"format": {
"type": "string"
}
},
"required": [
"ms"
]
}