#pragma mark--时间戳转保准时间
- (NSString *)timerWith:(NSString *)time
{
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"yyyyMMdd"];
NSString *str = [NSString stringWithFormat:@"%@",[formatter stringFromDate:[NSDate dateWithTimeIntervalSince1970:[time intValue]]]];
return str;
}
//标准时间转时间戳
- (NSString *)change:(NSString *)timeStr
{
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"yyyyMMdd"];
NSDate* date1 = [formatter dateFromString:timeStr];
NSString *timeSp = [NSString stringWithFormat:@"%ld", (long)[date1 timeIntervalSince1970]];
return timeSp;
}
NSDate *nowDate1 = [NSDate date];
NSTimeZone *zone = [NSTimeZone systemTimeZone];
NSInteger interval = [zone secondsFromGMTForDate:nowDate1];
NSDate *nowDate = [nowDate1 dateByAddingTimeInterval:interval];
NSLog(@"dat==%@",nowDate);
- (int)intervalSinceNow: (NSString *) theDate
{
NSDateFormatter *formatter=[[NSDateFormatter alloc] init];
[formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
NSDate *d=[formatter dateFromString:theDate];
NSTimeInterval late=[d timeIntervalSince1970]*1;
NSDate *nowDate1 = [NSDate date];
NSTimeInterval now=[nowDate1 timeIntervalSince1970]*1;
NSString *timeString=@"";
NSTimeInterval cha=now-late;
if (cha/86400>0)
{
timeString = [NSString stringWithFormat:@"%f", cha/86400];
NSLog(@"timer1111==%@",timeString);
timeString = [timeString substringToIndex:timeString.length-7];
int timeInt = [timeString intValue]+1;
NSLog(@"timer==%@",timeString);
return timeInt;
}
return 1;
}
-(NSString *)getFutureDate:(NSInteger)day
{
NSDate *nowDate = [NSDate date];
NSDate *theDate;
if (day!=0)
{
NSTimeInterval oneDay = 24*60*60*1;
theDate = [nowDate initWithTimeIntervalSinceNow:oneDay*day];
}
else
{
theDate = nowDate;
}
NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
[formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
NSString *futureDateStr = [formatter stringFromDate:theDate];
return futureDateStr;
}