views:

255

answers:

1

Hi all,

I am new to the whole iPhone SDK and objective C, but have managed to get three times, two pulled from RSS feed, and one from the iphone. I currently have: sunrise, sunset and current time set like:

    6:51 am //Sunrise
    7:36 pm //Sunset
    11:34 AM //Current time

I am trying to work out the best approach to find out if its day or night? Any help on this welcome, thanks in advance.

+2  A: 

Use NSDateFormatter to create NSDate objects from your dates.

- (NSDate *)dateFromString:(NSString *)string

In NSDate you have: earlierDate, laterDate and compare that you can use.

For day time you want:

currentTime >= sunrise && < sunset

for night time you want:

currentTime >= sunset && < sunrise

Pseudo code :)

willcodejavaforfood