Is there a better way than this?
Boolean isNight;
Calendar cal = Calendar.getInstance();
int hour = cal.get(Calendar.HOUR_OF_DAY);
if(hour < 6 || hour > 18){
isNight = true;
} else {
isNight = false;
}
It just checks if hour is between 7pm and 5am. Is there any other way to do this?
Not a big difference, but you can make an assignment:
isNight = hour < 6 || hour > 18;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With