iOS-获取任意时间的零点和二十四点时间戳字符串

   // 输入时间戳字符串,获取那天零点和二十四点时间戳
- (void)timeStrTest{
    
    // 时间戳字符串+时间格式
    NSString * createTimeStr = @"1320805779000";
    NSString * formatStr = @"YYYY-MM-dd";
 
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateStyle:NSDateFormatterMediumStyle];
    [dateFormatter setTimeStyle:NSDateFormatterShortStyle];
    [dateFormatter setDateFormat:formatStr];
    
    NSTimeInterval time = [createTimeStr doubleValue] / 1000 ;
    NSDate *detaildate = [NSDate dateWithTimeIntervalSince1970:time] ;
    NSString *currentTimeString = [dateFormatter stringFromDate: detaildate];
    NSDate* result = [dateFormatter dateFromString:currentTimeString];
    
    // 计算零点时间戳
    NSTimeInterval timeZreoInt=[result timeIntervalSince1970] * 1000;
    NSString *timeZreoString = [NSString stringWithFormat:@"%.0f", timeZreoInt];
    
    // 计算二十四点时间戳
    NSTimeInterval timeTenInt = timeZreoInt + 86400000;
    NSString *timeTenString = [NSString stringWithFormat:@"%.0f", timeTenInt];
    
    NSLog(@"%@===%@===KK",timeZreoString,timeTenString);
}

你可能感兴趣的:(iOS-获取任意时间的零点和二十四点时间戳字符串)