本段代碼的主要功能是取出裝滿標(biāo)準(zhǔn)時(shí)間的數(shù)組里邊最大的值。并以標(biāo)準(zhǔn)時(shí)間輸出
NSMutableArray *arrayMSecond = [NSMutableArray arrayWithCapacity:2];
for(NSString *date in arrayM){
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateStyle:NSDateFormatterMediumStyle];
[formatter setTimeStyle:NSDateFormatterShortStyle];
[formatter setDateFormat:@"YYYY-MM-dd HH:mm:ss"];
//設(shè)置時(shí)區(qū),這個(gè)對(duì)于時(shí)間的處理有時(shí)很重要
NSTimeZone* timeZone = [NSTimeZone timeZoneWithName:@"Asia/Beijing"];
[formatter setTimeZone:timeZone];
NSDate* dateSecond = [formatter dateFromString:date]; //------------將字符串按formatter轉(zhuǎn)成nsdate
//時(shí)間轉(zhuǎn)時(shí)間戳的方法:
NSInteger timeSp = [[NSNumber numberWithDouble:[dateSecond timeIntervalSince1970]] integerValue];
[arrayMSecond addObject:@(timeSp)];
}
NSInteger max = [[arrayMSecond objectAtIndex:0] integerValue];
for (int i=0; i<arrayMSecond.count-1; i++) {
if(max < [[arrayMSecond objectAtIndex:i+1] integerValue]){
max = [[arrayMSecond objectAtIndex:i+1] integerValue];
}
}
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateStyle:NSDateFormatterMediumStyle];
[formatter setTimeStyle:NSDateFormatterShortStyle];
[formatter setDateFormat:@"YYYY-MM-dd HH:mm:ss"]; //----------設(shè)置你想要的格式,hh與HH的區(qū)別:分別表示12小時(shí)制,24小時(shí)制
//設(shè)置時(shí)區(qū),這個(gè)對(duì)于時(shí)間的處理有時(shí)很重要
NSTimeZone *timeZone = [NSTimeZone timeZoneWithName:@"Asia/Beijing"];
[formatter setTimeZone:timeZone];
NSDate *confromTimesp = [NSDate dateWithTimeIntervalSince1970:max];
NSString *confromTimespStr = [formatter stringFromDate:confromTimesp];
self.presellEndDate = confromTimespStr;