NSSting 轉(zhuǎn) NSDate
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];//設(shè)置你想要的格式,hh與HH的區(qū)別:分別表示12小時(shí)制,24小時(shí)制
NSDate *date = [dateFormatter dateFromString:resultString];
NSDate 轉(zhuǎn) NSString
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
NSString *strDate = [dateFormatter stringFromDate:[NSDate date]];
獲取本地 NSDate
NSTimeZone *timeZone = [NSTimeZone systemTimeZone];
NSInteger interval = [timeZone secondsFromGMTForDate: date];
NSDate *localeDate = [date dateByAddingTimeInterval: interval];
時(shí)區(qū)轉(zhuǎn)換
NSDateFormatter *Formatter = [[NSDateFormatter alloc] init];
[Formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
[Formatter setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"UTC"]];
NSString *strDate = [Formatter stringFromDate:localeDate];
NSLog(@"%@", strDate);
NSDate 轉(zhuǎn)時(shí)間戳
NSDate *date = [NSDate date];
NSString *timeSp = [NSString stringWithFormat:@"%ld", (long)[date timeIntervalSince1970]];
時(shí)間戳轉(zhuǎn) NSDate
NSDate *date = [NSDate date];
NSTimeInterval timeInterval = [date timeIntervalSince1970]-1800;//前30分鐘
NSDate *newdate = [NSDate dateWithTimeIntervalSince1970:timeInterval];