iOS-计算两个日期之间的天数
2015-08-05 10:28
423 查看
//计算两个日期之间的天数
+ (NSInteger) calcDaysFromBegin:(NSDate *)beginDate end:(NSDate *)endDate
{
//创建日期格式化对象
NSDateFormatter *dateFormatter=[[NSDateFormatter
alloc]
init];
[dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm"];
//取两个日期对象的时间间隔:
//这里的NSTimeInterval
并不是对象,是基本型,其实是double类型,是由c定义的:typedef double NSTimeInterval;
NSTimeInterval time=[endDate
timeIntervalSinceDate:beginDate];
int days=((int)time)/(3600*24);
//int hours=((int)time)%(3600*24)/3600;
//NSString *dateContent=[[NSString alloc] initWithFormat:@"%i天%i小时",days,hours];
return days;
}
+ (NSInteger) calcDaysFromBegin:(NSDate *)beginDate end:(NSDate *)endDate
{
//创建日期格式化对象
NSDateFormatter *dateFormatter=[[NSDateFormatter
alloc]
init];
[dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm"];
//取两个日期对象的时间间隔:
//这里的NSTimeInterval
并不是对象,是基本型,其实是double类型,是由c定义的:typedef double NSTimeInterval;
NSTimeInterval time=[endDate
timeIntervalSinceDate:beginDate];
int days=((int)time)/(3600*24);
//int hours=((int)time)%(3600*24)/3600;
//NSString *dateContent=[[NSString alloc] initWithFormat:@"%i天%i小时",days,hours];
return days;
}
相关文章推荐
- iOS 对应用程序启动时所有方法的调用顺序分析(转自董铂然博客园)
- 苹果IOS开发者账号的区别,企业账号,个人账号,公司团队账号,教育账号
- ios禁止屏幕旋转
- iOS 7中的extendedLayout
- 利用dwarfdump 分析IOS crash
- iOS-基本知识汇总
- iOS 读书笔记-cookie
- iOS在照片上添加水印
- iOS 开发的中英文入门推荐书籍都有哪些?
- IOS Xcode 插件
- iOS图形库CorePlot
- xcode语法高亮插件
- iOS7使用iOS8上的方法报错处理
- iOS开发中的测试框架
- iOS开发_常用的正则表达式
- iOS开发基础之用三种不同方式创建Table View应用
- iOS项目的完整重命名方法图文教程
- iOS证书与推送通知证书制作过程遇到的问题
- IOS中的代理模式
- iOS开发基础之用三种不同方式创建Table View应用