Created 03-06-2023 08:50 AM
I have a feed coming in with time spent value set in seconds. Example 900 or 3600
Is there way in nifi to convert attribute to 00:15 and 01:00 (HH:mm format)?
Created on 03-07-2023 01:04 AM - edited 03-07-2023 01:29 AM
I would try something like:
${value:divide(3600)}:${value:divide(60):mod(60)}
value = your attribute.
value:divide(3600) = identify the hours.
value:divide(60):mod(60) = identify the minutes.
Give it a try and let me know if it works fine for you 😀
LE:
If you want the leading 0 as well, if the hour value is lower then 10, try something like:
${value:divide(3600):lt(10):ifElse(${value:divide(3600):prepend(0)},${value:divide(3600)})}:${value:divide(60):mod(60)}
It is basically the same thing as before, but instead, you are using an IF-ELSE to check whether the the value for the hours is lower then 10 and if so, you append a leading 0 to it so it will display as 0X:MM. If the value is greater then 10, you stick with the original value, without adding any new zeros.
Created on 03-07-2023 01:04 AM - edited 03-07-2023 01:29 AM
I would try something like:
${value:divide(3600)}:${value:divide(60):mod(60)}
value = your attribute.
value:divide(3600) = identify the hours.
value:divide(60):mod(60) = identify the minutes.
Give it a try and let me know if it works fine for you 😀
LE:
If you want the leading 0 as well, if the hour value is lower then 10, try something like:
${value:divide(3600):lt(10):ifElse(${value:divide(3600):prepend(0)},${value:divide(3600)})}:${value:divide(60):mod(60)}
It is basically the same thing as before, but instead, you are using an IF-ELSE to check whether the the value for the hours is lower then 10 and if so, you append a leading 0 to it so it will display as 0X:MM. If the value is greater then 10, you stick with the original value, without adding any new zeros.
Created 03-08-2023 07:44 AM
@GSB
If you wanted it always to be two digits, you would need to apply the same if/else NiFi Expression Language (NEL) logic the minute calculations in the working solution provided by @cotopaul
${value:divide(3600):lt(10):ifElse(${value:divide(3600):prepend(0)},${value:divide(3600)})}:${value:divide(60):mod(60):lt(10):ifElse(${value:divide(3600):mod(60):prepend(0)},${value:divide(3600):mod(60)})}
A simpler approach would be to use the toDate and Format NEL functions:
${value:toDate('sssss'):format('HH:mm')}
I allow 5 's' assuming that max value would be 86,500 seconds (24 hours in a day) and does not matter if value is smaller. This format also allows you to quickly and easily adjust format for example, maybe you don't want to truncate the remaining seconds and use ":format('HH:mm:ss')" instead.
If you found that the provided solution(s) assisted you with your query, please take a moment to login and click Accept as Solution below each response that helped.
Thank you,
Matt
Created 03-12-2023 11:09 PM
@GSB Have any of the replies helped resolve your issue? If so, please mark the appropriate reply as the solution, as it will make it easier for others to find the answer in the future.
Regards,
Vidya Sargur,