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

2016-05-18  本文已影响99人  Mustard_Buli

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

+(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];
上一篇下一篇

猜你喜欢

热点阅读