//1.时间格式
NSDateFormatter *_dateFormatter = [[NSDateFormatter alloc] init];
[_dateFormatter setDateFormat:@"YYYY年MM月dd天hh小时mm分ss秒"];
//2.获取系统时间
NSString *date = [_dateFormatter stringFromDate:[NSDate date]];
//3.NSDate转化为时间戳
NSTimeInterval a=[date timeIntervalSince1970];
//4.时间戳转化为NSDate
NSDate *stampDate = [NSDate dateWithTimeIntervalSince1970:timeInter];
//4.NSDate转化为NSString
NSString* dateString = [_dateFormatter stringFromDate:date];
//5.传入时间差,重置格式
//传入时间差,转换格式
- (NSString *)timeWithMessageString:(NSTimeInterval)timeInter
{
int month = timeInter / (3600 * 24 * 30);
int day = timeInter / (3600 * 24);
int hour = timeInter / 3600;
int minute = timeInter / 60;
int day_process = day - month * 30;
int hour_process = hour - day *24;
int minute_process = minute - hour *60;
int miao_process = timeInter - minute*60;
NSString *timedate = nil;
if (day == 0) {
timedate = [NSString stringWithFormat:@"%d小时%d分%d秒",hour_process,minute_process,miao_process];
if (hour == 0) {
timedate = [NSString stringWithFormat:@"%d分%d秒",minute_process,miao_process];
if (hour == 0) {
timedate = [NSString stringWithFormat:@"%d秒",miao_process];
}
}
}else{
timedate = [NSString stringWithFormat:@"%d天%d小时%d分%d秒",day_process,hour_process,minute_process,miao_process];
}
timedate = [NSString stringWithFormat:@"限时优惠: 还剩%@",timedate];
return timedate;
}
//当前时间的半小时后
NSDate *date1 = [NSDate date];
NSDate *date2 = [[NSDate date] dateByAddingTimeInterval: 30*60];
NSDate *date3 = [NSDate dateWithTimeIntervalSinceNow:30*60];