I would like some opinions/help with creating a fairly simple function, here are the requirements:
I need to determine if the current time is day or night (Day is between 6am and 6pm). For example here is some pseudo code:
if(currentTime < 6pm && currentTime > 6am){
return timeIsDay
}
else{
return timeIsNight
}
This is for an IOS application in Objective C and MUST be IOS 8.0 compatible.
Try this
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"HH.mm"];
NSString *strCurrentTime = [dateFormatter stringFromDate:[NSDate date]];
NSLog(@"Check float value: %.2f",[strCurrentTime floatValue]);
if ([strCurrentTime floatValue] >= 18.00 || [strCurrentTime floatValue] <= 6.00){
NSLog(@"It's night time");
}else{
NSLog(@"It's day time");
}
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