如何检查时间是否是白天/夜晚目标C [复制](How to check if time is day/night Objective C [duplicate])

编程入门 行业动态 更新时间:2024-10-18 16:45:40
如何检查时间是否是白天/夜晚目标C [复制](How to check if time is day/night Objective C [duplicate])

这个问题在这里已经有了答案:

ios-检查当前时间是否在两次或三次之间

我想要创建一个相当简单的功能的一些意见/帮助,这里是要求:

我需要确定当前时间是白天还是晚上(白天是早上6点到晚上6点)。 例如这里是一些伪代码:

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

这是Objective C中的IOS应用程序,必须与IOS 8.0兼容。

This question already has an answer here:

ios- Check whether current time is between two times or not 4 answers

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.

最满意答案

尝试这个

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"); }

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"); }

更多推荐

本文发布于:2023-07-25 05:42:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1256792.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:夜晚   白天   目标   时间   check

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!