美文网首页
时间戳转换、获取当前国家/语言

时间戳转换、获取当前国家/语言

作者: Mustard_Buli | 来源:发表于2016-05-18 08:45 被阅读99次

    将时间戳转化为距当前时间的天数

    +(int) daysRangeWithToday:(NSString *) timestamp
    {
        long long time = timestamp.longLongValue / 1000;
        NSDate *serverDate = [NSDate dateWithTimeIntervalSince1970:time];
        NSDate *endDate = [NSDate date];
        NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
        [gregorian setFirstWeekday:2];
        
        NSDate *fromDate;
        NSDate *toDate;
        [gregorian rangeOfUnit:NSCalendarUnitDay startDate:&fromDate interval:NULL forDate:serverDate];
        [gregorian rangeOfUnit:NSCalendarUnitDay startDate:&toDate interval:NULL forDate:endDate];
        NSDateComponents *dayComponents = [gregorian components:NSCalendarUnitDay fromDate:fromDate toDate:toDate options:0];
        
        return dayComponents.day;
    }
    

    获取当前的国家/语言

    NSString* strLanguage = [[[NSUserDefaults standardUserDefaults] objectForKey:@"AppleLanguages"] objectAtIndex:0];
    

    相关文章

      网友评论

          本文标题:时间戳转换、获取当前国家/语言

          本文链接:https://www.haomeiwen.com/subject/jmxwrttx.html