NSTimeInterval secondsPerDay1 = 24*60*60; NSDate *now = [NSDate date]; NSDate *yesterDay = [now addTimeInterval:-secondsPerDay1]; //若是是就去掉負號 NSDateFormatter * formatter=[[NSDateFormatter alloc]init]; [formatter setDateFormat:@"yyyy-MM-dd"]; NSString *rq=[formatter stringFromDate:yesterDay]; NSLog(@"%@",rq);
//時間戳轉換成日期 NSDateFormatter * formatter=[[NSDateFormatter alloc]init]; [formatter setDateFormat:@"MM-dd HH:mm"]; NSInteger time=[[dic objectForKey:@"add_time"] integerValue]; NSDate *confromTimesp = [NSDate dateWithTimeIntervalSince1970:time]; dateLabel.text=[formatter stringFromDate:confromTimesp];