问题描述
我使用日期时间选择器来获取两个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参考是一个很棒的小文档:
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之间的差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!