Cocoa-Touch:如何查看两个NSDates是否在同一天? [英] Cocoa-Touch: How do I see if two NSDates are in the same day?

查看:137
本文介绍了Cocoa-Touch:如何查看两个NSDates是否在同一天?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要知道两个NSDate实例是否都是同一天。

I need to know if two NSDate instances are both from the same day.

是否有一个更容易/更好的方法来做NSDateComponents和比较日/ month / year?

Is there an easier/better way to do it than getting the NSDateComponents and comparing day/month/year?

推荐答案

NSDateComponents听起来像是最好的打赌。另一种尝试尝试的策略是将其免费桥接到CFDate,然后使用CFDateGetAbsoluteTime并执行减法以获得两个日期之间的时间量。你必须做一些额外的数学计算,以确定时差是否在同一天的日期。

NSDateComponents sounds like the best bet to me. Another tactic to try is toll-free-bridging it to a CFDate, then using CFDateGetAbsoluteTime and doing a subtraction to get the amount of time between the two dates. You'll have to do some additional math to figure out if the time difference lands the dates on the same day, however.

这篇关于Cocoa-Touch:如何查看两个NSDates是否在同一天?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆