Transform datetime to string

I use the following transform in a watcher

"transform": {
    "script": {
      "source": "return [ 'time_triggered': Instant.ofEpochMilli(ctx.trigger.triggered_time.getMillis()).atZone(ZoneId.of('Europe/Copenhagen')) ]",
      "lang": "painless"
    }
  }

Which outputs a timestamp like
2018-08-16T10:13:58.698+02:00[Europe/Copenhagen]

Instead I would like to be able to insert this output in an email action.
2018-08-16 10:13:58

How do I get that string?

try using a date formatter (new lines for the sake of readability)

return [ 'time_triggered': Instant.ofEpochMilli(ctx.trigger.triggered_time.getMillis())
.atZone(ZoneId.of('Europe/Copenhagen'))
.format(DateTimeFormatter.ofPattern('YYYY-MM-dd HH:mm:ss')) ]

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.