How to check if time is day / night Objective C

I would like some opinions / help on creating a fairly simple function, here are the requirements:

I need to determine if the current time is day or night (day between 6am and 6pm). For example, here's some pseudo code:

if(currentTime < 6pm && currentTime > 6am){
     return timeIsDay
     return timeIsNight


This is for an IOS app in Objective C and MUST be compatible with IOS 8.0.


source to share

1 answer

try it

NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@""];
    NSString *strCurrentTime = [dateFormatter stringFromDate:[NSDate date]];

NSLog(@"Check float value: %.2f",[strCurrentTime floatValue]);
    if ([strCurrentTime floatValue] >= 18.00 || [strCurrentTime floatValue]  <= 6.00){
        NSLog(@"It night time");
        NSLog(@"It day time");




All Articles