------Java培训、Android培训、iOS培训、.Net培训、期待与您交流! -------
NSNumber 继承于 NSValue
1、将基本数据类型转为OC对象
NSNumber *n = [NSNumber numberWithInt:10];
NSString *n1=[NSString stringWithFormat:@"%d",10];
2、将OC对象转为基本类型
int a = [n intValue];
int a1 = [@"20" intValue];
Xcode下特性:
@20.3;
@YES;
@'A'; // NSNumber对象
@"A"; // NSString对象
int age=10; @(age); // 将age变量包装成NSNumber对象,小括号的使用
CGPoint p = CGPointMake(10,10);
NSValue *value = [NSValue valueWithPoint:p]; // 结构体-->OC对象
CGPoint p1 = [value pointValue]; // OC对象-->结构体
NSDate
NSDate *date = [NSDate date];//创建一个时间,初始化值为当前时间
NSDate *date2 = [NSDate dateWithTimeInterval:5 sinceDate:date]; // 创建一个比date晚5秒的时间
NSTimeInterval senconds = [date2 timeIntervalSince1970]; // 从1970到date2的毫秒值 NSTimeInterval本质是double
[date2 timeIntervalSinceNow]; // 从现在到date2的毫秒值
NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
formatter.dateFormat = @"yy-MM-dd HH:mm:ss"; // HH为24小时制 hh为12小时制
NSString *str = [formatter stringFromDate:date]; // 将date格式化为上面的格式
const char *s= [str UTF8String];
NSDate*date3 = [formatter dateFromString:str]; // 将str字符串转为Date对象
printf("%s\n",s);
NSLog(@"%@",date3);
------Java培训、Android培训、iOS培训、.Net培训、期待与您交流! -------