与 iphone SDK 比较时间/日期

发布于 2024-08-27 02:18:39 字数 260 浏览 3 评论 0原文

我对整个 iPhone SDK 和 Objective C 都很陌生,但已经成功获得了 3 次,其中两次是从 RSS feed 中提取的,一次是从 iphone 中提取的。 我目前有:日出、日落和当前时间设置如下:

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

我正在尝试找出最好的方法来确定现在是白天还是晚上? 对此欢迎任何帮助,提前致谢。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

咆哮 2024-09-03 02:18:39

使用 NSDateFormatter从您的日期创建 NSDate 对象。

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

NSDate你有:
您可以使用 earlierDatelaterDatecompare

白天您想要:

当前时间>=日出&& <日落

您想要的夜间

时间:

当前时间>=日落&& <日出

伪代码:)

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文