datetime
Syntax
identifier:
type: datetime
format: string
utc: boolean
timezone: string
interval: interval
- identifier is the name of the identifier that will represent the date/time value.
- type: Must be set to the value
datetime
. Indicates this is a datetime generator. - format: The formatted value of the date/time. See Formatting below.
- interval: The time interval between each update.
- utc: (deprecated) Whether date/time is formatted in UTC or local time.
- timezone: The timezone the date/time should be interpreted in before formatting.
Description
The datetime generator is a self-contained data source that periodically updates a value with a formatted date/time string.
The format option can be used to change the contents of the date/time string. If a format isn't specified,
the value will be formatted as an ISO 8601 string without the timezone offset. This is equivalent to the format
string YYYY-MM-DDTHH:mm:ss
.
The utc option specifies whether dates are formatted in UTC or local time. Local time uses the timezone off the edge device that the adapter script is running on, which may not match the intended local time. The UTC option is true by default. This option is deprecated in favor of the timezone option, as there may before no control over the local time of the edge device.
The timezone option takes a TZ identifier such as America/New_York
to specify the timezone that the date/time
should be formatted in.
The interval option specifies how often the value is updated. By default, the date/time value will be updated
every second. The interval is "aligned" to the start of the Unix epoch, rather than the start of the adapter
script's execution. If for example an interval of 20m
is specified, then the value update will reliably occur
at every 00, 20, and 40 minute-past-the-hour times.
Examples
- AdapterScript
generators:
timestamp:
type: datetime
format: X
interval: 5s
In the above example, timestamp
is the identifier that can be referenced by other parts of the adapter script.
This creates a value that's updated every 5 seconds with a unix timestamp. The generator is technically running in UTC mode, but that doesn't affect the output of timestamps.
Formatting
Dates and times are formatted according to a string of tokens supplied to the format
parameter. The following
tokens are supported:
Format | Output | Description |
---|---|---|
YY | 18 | Two-digit year |
YYYY | 2018 | Four-digit year |
M | 1-12 | The month, beginning at 1 |
MM | 01-12 | The month, 2-digits |
MMM | Jan-Dec | The abbreviated month name |
MMMM | January-December | The full month name |
Q | 1-4 | Quarter |
D | 1-31 | The day of the month |
Do | 1st 2nd ... 31st | Day of Month with ordinal |
DD | 01-31 | The day of the month, 2-digits |
d | 0-6 | The day of the week, with Sunday as 0 |
dd | Su-Sa | The min name of the day of the week |
ddd | Sun-Sat | The short name of the day of the week |
dddd | Sunday-Saturday | The name of the day of the week |
H | 0-23 | The hour |
HH | 00-23 | The hour, 2-digits |
h | 1-12 | The hour, 12-hour clock |
hh | 01-12 | The hour, 12-hour clock, 2-digits |
k | 1-24 | The hour, beginning at 1 |
kk | 01-24 | The hour, 2-digits, beginning at 1 |
m | 0-59 | The minute |
mm | 00-59 | The minute, 2-digits |
s | 0-59 | The second |
ss | 00-59 | The second, 2-digits |
SSS | 000-999 | The millisecond, 3-digits |
Z | +05:00 | The offset from UTC, ±HH:mm |
ZZ | +0500 | The offset from UTC, ±HHmm |
A | AM PM | |
a | am pm | |
X | 1360013296 | Unix timestamp |
x | 1360013296123 | Unix millisecond timestamp |
Characters can be escaped by wrapping them in square brackets (e.g. [MM]
).