如何获取当天某个时间
/** * 获取当天凌晨时间 */
NSTimeZone *gmt = [NSTimeZone timeZoneWithAbbreviation:@"GMT"];
NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier: NSCalendarIdentifierGregorian];
[calendar setTimeZone:gmt];
NSDate *date = [NSDate date];
NSDateComponents *components = [calendar components:NSUIntegerMax fromDate:date];
components.day-=1;
[components setHour:0];
[components setMinute:0];
[components setSecond: 0];
NSDate *startDate = [calendar dateFromComponents:components];
NSDate *endDate = [calendar dateByAddingUnit:NSCalendarUnitDay value:1 toDate:startDate options:0];
WSLog(@"%@", endDate);
时间转化为时间戳
/** * 时间转化为时间戳 */
NSTimeInterval a=[endDate timeIntervalSince1970]*1000;
NSString *timeString = [NSString stringWithFormat:@"%.0f", a];
WSLog(@"%@",timeString);
时间戳转化为时间
/** * 获取时间戳 * 网络请求获取的数据 * getTime为网上获取的时间戳 */
NSTimeInterval _interval=[getTime doubleValue] / 1000.0;
NSDateFormatter *objDateformat = [[NSDateFormatter alloc] init];
[objDateformat setDateFormat:@"yyyy-MM-dd"];
NSString *dateString = [objDateformat stringFromDate:date];
NSString *monthString = [dateString substringWithRange:NSMakeRange(5, 2)];