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.263-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"
}
[
"2024-03-14 00:46:49.148",
"2023-11-10 22:09:32.645",
"2024-03-25 22:00:50.727",
"2023-12-09 08:35:42.000",
"2024-02-28 19:54:07.062"
]

Set the timezone​

By default, all timestamps are printed in UTC, but you can change this by supplying a timezone parameter. The value of timezone must correspond to a JodaTime timezone ID (like Asia/Bahrain) or the value System, which will pick up the default timezone on the system where ShadowTraffic is currently running.

{
"_gen": "formatDateTime",
"ms": {
"_gen": "now"
},
"timezone": "America/Los_Angeles"
}
[
"2024-04-25T13:28:47.263-07:00"
]

Specification​

JSON schema​

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