Search code examples
apache-nifi

Calculate when the next hour will start


How can I calculate time in epoch ms, when the next hour will start? I mean for example now I've a 19.45, next hour is - 20.00. I want to get this time (20.00 in epoch) and store it as attribute. If now time is 20.12, next hour is - 21.00 etc. So not just simple add one hour to current time.


Solution

  • It's possible with an UpdateAttribute processor:

    • next-hour: ${now():plus(3599999):format("yyyy-MM-dd HH"):toDate("yyyy-MM-dd HH"):toNumber()}

    Example:

    • now() => 1696323223639
    • next-hour => 1696323600000