Transform datetime to string

alerting

#1

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?


(Alexander Reelsen) #2

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')) ]

(system) #3

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