码迷,mamicode.com
首页 > 移动开发 > 详细

iOS 计算 日期 距离 当前 系统的日期 相差 多少

时间:2015-07-03 23:20:06      阅读:209      评论:0      收藏:0      [点我收藏+]

标签:

#pragma mark - 时间计算函数

 - (NSTimeInterval)intervalSinceNow:(NSString *) theDate

{

    NSDateFormatter * date = [[NSDateFormatter alloc] init];

    [date setDateFormat:@"yyyy年MM月dd日 HH:mm"];

    NSDate * d = [date dateFromString:theDate];

    NSTimeInterval late = [d timeIntervalSinceNow]*1;  // late  单位是 秒

    return late;

}

 

    /**

     *  

     传入  theDate -- 2015年03月03日 00:00

     得到  d -- 2015-03-02 16:00:00 +0000

     late -- -10619772.913287

     */

    

大家可以看到 时间 d 并 不等于  theDate   原因是 给传入的时间   系统是默认为是中国的时间    北京的时间比美国 多 8 个小时 所以  转换出来 是 d 比 theDate 早了8小时 转换出来的是美国的时间   

 

iOS 计算 日期 距离 当前 系统的日期 相差 多少

标签:

原文地址:http://www.cnblogs.com/isItOk/p/4619854.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!