方法一

文本復(fù)制:
//第一種:
NSDateFormatter*dateFormatter = [[NSDateFormatteralloc]init];
//設(shè)置UTC時(shí)間格式
//2016-05-21T06:40:05Z
[dateFormattersetDateFormat:@"yyyy-MM-dd'T'HH:mm:ssZ"];
//轉(zhuǎn)換貸款日期為NSDate
NSDate*postedDate = [dateFormatterdateFromString:@"此處是你的時(shí)間"];
//獲取當(dāng)前時(shí)間對應(yīng)的NSData
NSDate*currentDate = [NSDatedate];
//轉(zhuǎn)換截至日期為NSDate
NSDate*plannedDate = [dateFormatterdateFromString:@"此處是你的時(shí)間"];
//結(jié)算兩個(gè)date的時(shí)間差(單位:秒)
NSTimeIntervaltimeInterval = [plannedDatetimeIntervalSinceDate:currentDate];
方法二

文本復(fù)制:
//第二種:
NSDateFormatter*f = [NSDateFormatternew];
//設(shè)置格式Mon Aug 15 15:36:17 +0800 2016
f.dateFormat=@"EEE MMM dd HH:mm:ss Z yyyy";
//設(shè)置時(shí)區(qū)
f.locale= [[NSLocalealloc]initWithLocaleIdentifier:@"en_US"];
//得到微博發(fā)送的Date對象
NSDate*weiboDate = [fdateFromString:@"此處是你的時(shí)間"];
NSDate*nowDate = [NSDatenew];
//微博時(shí)間
longcreateTime = [weiboDatetimeIntervalSince1970];
//當(dāng)前時(shí)間
longnowTime = [nowDatetimeIntervalSince1970];
longtime = nowTime - createTime;