Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Format current date and time at UTC in Apache Camel

Tags:

apache-camel

I am implementing integration with external service which requires current date and time. The documentation of the service says that it accepts the datetime in ISO 8601 format, but that's only partially true – it doesn't support timezone offset.

When I try ${date:now:yyyy-MM-dd'T'HH:mm:ssZ} in Camel, I get 2017-08-16T21:45:10+0200, which is not acceptable by the service.

Is there a way to make Camel date format output current date in UTC? I would like to get 2017-08-16T19:45:10Z instead of 2017-08-16T21:45:10+0200.

I would like to avoid writing separate bean for that, so I prefer solution implemented purely in XML DSL.

like image 806
Archie Avatar asked Aug 16 '17 20:08

Archie


1 Answers

I've managed to come up with a solution using Groovy expression:

<groovy>
  java.time.ZonedDateTime.now(java.time.ZoneOffset.UTC)
      .format(java.time.format.DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ssX"))
</groovy>
like image 150
Archie Avatar answered Sep 21 '22 21:09

Archie