獲取系統(tǒng)當(dāng)前時(shí)間
NSDate * senddate=[NSDate date];
NSDateFormatter *dateformatter=[[NSDateFormatter alloc] init];
//設(shè)置獲取時(shí)間的格式
[dateformatter setDateFormat:@"yyyyMMddHHmmss"];
NSString * locationString=[dateformatter stringFromDate:senddate];
時(shí)間戳轉(zhuǎn)換為時(shí)間
NSDateFormatter* formatter = [[NSDateFormatter alloc] init];
[formatter setDateStyle:NSDateFormatterMediumStyle];
[formatter setTimeStyle:NSDateFormatterShortStyle];
[formatter setDateFormat:format];//@"yyyy-MM-dd-HHMMss"
NSDate* date = [NSDate dateWithTimeIntervalSince1970:[timestamp doubleValue]];
NSString* dateString = [formatter stringFromDate:date];
日期加N個(gè)月
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"yyyy/MM/dd"];
NSDate *date = [formatter dateFromString:dateString];
[formatter setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"UTC"]];
NSCalendar *gregorian = [[NSCalendar alloc]
initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
NSDateComponents* dc1 = [[NSDateComponents alloc] init];
//需要加的月數(shù)
[dc1 setMonth:count];
NSDate *nextmonthDate = [ gregorian dateByAddingComponents:dc1 toDate:date options:0];
return [formatter stringFromDate:nextmonthDate];
工具類下載地址
里面包含其他日期轉(zhuǎn)換的相關(guān)方法
戳我下載~~~