0
点赞
收藏
分享

微信扫一扫

NSDate 当前时间获取和时间比较



代码来源:(取自微博项目)

#import "IWAccountTool.h"
#import "IWAccount.h"


#define IWAccountFile [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject] stringByAppendingString:@"account.data"]


@implementation IWAccountTool
+(void)saveAccount:(IWAccount *)account
{
    //这是当前的时间值
    NSDate   *now = [NSDate  date];
    //这是当前时间加上一个timeout的值
    account.expiresTime = [now dateByAddingTimeInterval:account.expires_in];
    
    [NSKeyedArchiver archiveRootObject:account toFile:IWAccountFile];
}
+(IWAccount *)account
{
    IWAccount *account =  [NSKeyedUnarchiver  unarchiveObjectWithFile:IWAccountFile];
    //判断是否过期
    NSDate  *now = [NSDate  date];
    //返回结果是升序还是降序
    if ([now compare:account.expiresTime] == NSOrderedAscending) {
       // NSLog(@"now is %@ -%@",now,account.expiresTime);
        //后者大,代表没有过期
        return account;
    }else{
    //前者大,代表已经过期
    return nil;
    }
}
@end




举报

相关推荐

0 条评论