1、 数组的使用
------
NSNumber *num=[[NSNumber alloc] initWithInt:1];//转化成对象
NSArray *arr=[[NSArray alloc] initWithObjects:num,nil];//数组的建立
for (int i=0; i<[arr count]; i++) {//普通遍历
NSLog(@"-=-=");
}
for (NSNumber *n in arr){//泛型遍历
NSLog(@"22");
}
//定义一个可变数组
NSMutableArray *muarr=[[NSMutableArray alloc] initWithObjects:num,nil];
[muarr addObject:arr];//添加一个数组
[muarr replaceObjectAtIndex:1 withObject:num];//替换指定的值
--------------------------
-------------------------
2、时间处理
#import <Foundation/Foundation.h>
int main (int argc, const char * argv[])
{
@autoreleasepool {
// // insert code here...
NSLog(@"Hello, World!");
NSDate * date = [NSDate date];
NSLog(@"NSDATA: %@", date);
//NSdate的数据提取出来
NSDate *now = [NSDate date];
NSCalendar *cal = [NSCalendar currentCalendar];
unsigned int unitFlags = NSWeekdayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit | NSYearCalendarUnit;
NSDateComponents *dd = [cal components:unitFlags fromDate:now];
NSInteger week = [dd weekday];
NSInteger hour = [dd hour];
NSInteger minute = [dd minute];
NSInteger year = [dd year];
NSLog(@"week = %ld",week);
NSLog(@"hour = %ld",hour);
NSLog(@"minute = %ld",minute);
NSLog(@"year = %ld",year);
// NSCalendarDate * date2 = [NSCalendarDate date];
// NSInteger year = [date2 yearOfCommonEra];
// NSLog(@"year = %ld",year);
//格式化日期
NSDateFormatter *formatter =[[[NSDateFormatter alloc] init] autorelease];
[formatter setDateFormat:@"yyyy年M月dd日 H点m分"];
NSString *str = [NSString stringWithFormat:@"%@",
[formatter stringFromDate:date]];
NSLog(@"str:%@",str);
}
return 0;
}
结果:
2013-07-24 19:04:04.263 2013-7-24作业1[453:303] Hello, World!
2013-07-24 19:04:04.268 2013-7-24作业1[453:303] NSDATA: 2013-07-24 11:04:04 +0000
2013-07-24 19:04:04.269 2013-7-24作业1[453:303] week = 4
2013-07-24 19:04:04.269 2013-7-24作业1[453:303] hour = 19
2013-07-24 19:04:04.270 2013-7-24作业1[453:303] minute = 4
2013-07-24 19:04:04.270 2013-7-24作业1[453:303] year = 2013
2013-07-24 19:04:04.271 2013-7-24作业1[453:303] str:2013年7月24日 19点4分