两个NSDates之间的差异 [英] Difference between two NSDates

查看:98
本文介绍了两个NSDates之间的差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用日期时间选择器来获取两个NSDate。现在我想计算这两个NSDates之间的天数。我怎样才能找到两个NSDates之间的区别。

I am taking two NSDates by using date time picker. Now I want to count the number of days between these two NSDates. How can I find the difference between two NSDates.

请给我一些解决方案。

非常感谢。

推荐答案

NSDate参考是一个很棒的小文档:
http://developer.apple.com/library/mac/#documentation/Cocoa/Reference /Foundation/Classes/NSDate_Class/Reference/Reference.html

NSDate reference is a great little document: http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSDate_Class/Reference/Reference.html

- (NSTimeInterval)timeIntervalSinceDate:(NSDate *)anotherDate

如果你想要时间间隔差异,你正在寻找。

is what you are looking for if you want time interval difference.

几天(因为不是每天都有相同的分钟数,小时数)你想看到Martins在下面回答并使用NSDateComponents和[NSCalendar currentCalendar]

For days (as not every day has same number of minutes, hours) you want to see Martins answer below and use NSDateComponents with [NSCalendar currentCalendar]

这篇关于两个NSDates之间的差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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