根据时间戳获取日期+获取今天日期

//时间戳毫秒转日期
    NSDate *pDate = [NSDate dateWithTimeIntervalSince1970:indentify/1000];
    NSCalendar *pCalendar = nil;
    if ([UIDevice currentDevice].systemVersion.doubleValue >= 8.0) {
        pCalendar = [NSCalendar calendarWithIdentifier:NSCalendarIdentifierGregorian];
    } else {
        pCalendar = [NSCalendar currentCalendar];
    }
    //按照公历创建日期,
    NSDateComponents *pComponents = [pCalendar components:NSCalendarUnitYear|NSCalendarUnitMonth|NSCalendarUnitDay fromDate:pDate];
    //创建的Date是当前日期,默认时间为16:00:00(默认0时区) 即8时区的24:00:00,
    NSDate *pStartDate = [pCalendar dateFromComponents:pComponents];
    //StartDate加一天
    NSDate *pEndDate = [pCalendar dateByAddingUnit:NSCalendarUnitDay value:1 toDate:pStartDate options:0];


//获取今天的日期
    NSDate *pNowDate = [NSDate date];
    NSCalendar *pCalendar = nil;
    if ([UIDevice currentDevice].systemVersion.doubleValue >= 8.0) {
        pCalendar = [NSCalendar calendarWithIdentifier:NSCalendarIdentifierGregorian];
    } else {
        pCalendar = [NSCalendar currentCalendar];
    }
    //按照公历创建日期,
    NSDateComponents *pComponents = [pCalendar components:NSCalendarUnitYear|NSCalendarUnitMonth|NSCalendarUnitDay fromDate:pNowDate];
    //创建的Date是当前日期,默认时间为16:00:00(默认0时区) 即8时区的24:00:00
    NSDate *pStartDate = [pCalendar dateFromComponents:pComponents];
    //StartDate加一天
    NSDate *pEndDate = [pCalendar dateByAddingUnit:NSCalendarUnitDay value:1 toDate:pStartDate options:0];

你可能感兴趣的:(根据时间戳获取日期+获取今天日期)