When starting from ajava.util.date
object: what is the best way getting the hour part as an integer
regarding performance?
I have to iterat
In UTC:
int hour = (int)(date.getTime() % 86400000) / 3600000;
or
long hour = (date.getTime() % 86400000) / 3600000;
Date dateInput = new Date();
since calendar starts at 01.01.1970, 01:00
. you have to make further modifications
to the code.using below approach avoids that so this will performs faster.
dateInput.toInstant().atZone(ZoneId.systemDefault()).getHour();