Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android detect if night

Tags:

android

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?

like image 818
aperture Avatar asked Nov 23 '11 23:11

aperture


1 Answers

Not a big difference, but you can make an assignment:

isNight = hour < 6 || hour > 18;
like image 53
MByD Avatar answered Sep 19 '22 07:09

MByD