计算当前时间和指定时间的时间差
2015-12-30 14:50
323 查看
/** * 计算剩余时间 * * @param endTime 结束日期 * * @return 剩余时间 */ -(NSString *)getCountDownStringWithEndTime:(NSString *)endTime { NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm"]; NSDate *now = [NSDate date]; NSTimeZone *zone = [NSTimeZone systemTimeZone];//设置时区 NSInteger interval = [zone secondsFromGMTForDate: now]; NSDate *localDate = [now dateByAddingTimeInterval: interval]; endTime = [NSString stringWithFormat:@"%@ 23:59", endTime]; NSDate *endDate = [dateFormatter dateFromString:endTime]; NSInteger endInterval = [zone secondsFromGMTForDate: endDate]; NSDate *end = [endDate dateByAddingTimeInterval: endInterval]; NSUInteger voteCountTime = ([end timeIntervalSinceDate:localDate]) / 3600 / 24; NSString *timeStr = [NSString stringWithFormat:@"%d", voteCountTime]; return timeStr; }
这段代码计算出了相差几天
相关文章推荐
- 更改可以为空的列为非空
- 12.30 在一般处理程序页面使用Session
- excel条型图示例
- [LeetCode]题解(python):091-Decode Ways
- LeetCode OJ:Swap Nodes in Pairs(成对交换节点)
- jquery inArray()函数详解
- 奇怪!同一条sql语句在数据库和代码中执行结果不同?!当然是人错了 ……
- Photoshop中图层叠加效果的算法
- OC语言使用“消息结构”(messaging structure)而非“函数调用”(function calling)
- 画圆圈
- 使用Azure Redis Cache
- Photoshop中图层叠加效果的算法
- js库中$冲突的解决方法
- SVM基本思想和对偶推导笔记-记录毕业论文1
- 详解Nginx的核心配置模块中对于请求体的接受流程
- linux grep命令
- Libgdx学习笔记:UI之评分组件
- 详解likely和unlikely函数
- JavaScript 扩展内置函数
- MaterialRefreshLayout(下拉刷新和上拉加载)