intmain(intargc,constchar* argv[]) {
// ?c語(yǔ)言中 ?
NSDate*data1=[NSDatedate];
NSLog(@"%@",data1);
//時(shí)間傳喚
NSTimeZone*zone=[NSTimeZonesystemTimeZone];
NSIntegerseconds=[zonesecondsFromGMTForDate:data1];
NSDate*data2=[data1dateByAddingTimeInterval:seconds];
NSLog(@"%@",data2);
//??? y:年M:月d:日h:小時(shí)(24進(jìn)制) ? m:分s:秒
//時(shí)間格式規(guī)定
NSDateFormatter*formatter=[[NSDateFormatteralloc]init];
formatter.dateFormat=@"yyyy-MM-dd hh:mm:ss";
//時(shí)間與字符串轉(zhuǎn)喚
//時(shí)間轉(zhuǎn)換字符串,卵蛉,獲得的是當(dāng)前時(shí)區(qū)
NSString*dateStr=[formatterstringFromDate:data1];
NSLog(@"%@",dateStr);
//格尼時(shí)間
NSDate*date3=[formatterdateFromString:dateStr];
NSLog(@"%@",date3);
//時(shí)間日歷相關(guān)操作
NSCalendar*calendar=[[NSCalendaralloc]initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
NSCalendarUnitunit=NSCalendarUnitYear|NSCalendarUnitMonth|NSCalendarUnitDay|NSCalendarUnitHour|NSCalendarUnitMinute|NSCalendarUnitSecond;
NSDateComponents*components=[calendarcomponents:unitfromDate:data1];
NSLog(@"%ld",components.year);
NSLog(@"%ld",components.month);
NSLog(@"%ld",components.day);
NSLog(@"%ld",components.hour);
NSLog(@"%ld",components.minute);
NSLog(@"%ld",components.second);
return0;
//加個(gè)??
}