开发者

Comparing times/dates with the iphone SDK

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 t开发者_开发问答o find out if its day or night? Any help on this welcome, thanks in advance.


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 :)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜