Skip to main content

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

generators:
timestamp:
type: datetime
format: X
interval: 5s
info

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:

FormatOutputDescription
YY18Two-digit year
YYYY2018Four-digit year
M1-12The month, beginning at 1
MM01-12The month, 2-digits
MMMJan-DecThe abbreviated month name
MMMMJanuary-DecemberThe full month name
Q1-4Quarter
D1-31The day of the month
Do1st 2nd ... 31stDay of Month with ordinal
DD01-31The day of the month, 2-digits
d0-6The day of the week, with Sunday as 0
ddSu-SaThe min name of the day of the week
dddSun-SatThe short name of the day of the week
ddddSunday-SaturdayThe name of the day of the week
H0-23The hour
HH00-23The hour, 2-digits
h1-12The hour, 12-hour clock
hh01-12The hour, 12-hour clock, 2-digits
k1-24The hour, beginning at 1
kk01-24The hour, 2-digits, beginning at 1
m0-59The minute
mm00-59The minute, 2-digits
s0-59The second
ss00-59The second, 2-digits
SSS000-999The millisecond, 3-digits
Z+05:00The offset from UTC, ±HH:mm
ZZ+0500The offset from UTC, ±HHmm
AAM PM
aam pm
X1360013296Unix timestamp
x1360013296123Unix millisecond timestamp

Characters can be escaped by wrapping them in square brackets (e.g. [MM]).