大家一起学习,一起进步,有错的帮我提下,我会改的! //路径 NSBundle *strBundle = [NSBundle mainBundle]; NSLog(@"-----路径比较 %@",strBundle); NSString *str = NSHomeDirectory(); NSLog(@"-----路径二 %@",str); //当前日期 NSDate *date = [NSDate date]; NSLog(@"-----日期%@",date); //当前时间加上一定时间间隔 NSTimeInterval secondsPerDay = 2*24*60*60; NSDate *tomorrow = [NSDatedateWithTimeIntervalSinceNow:secondsPerDay]; NSLog(@"myDate = %@",tomorrow);
NSCalendar *calendar = [NSCalendar currentCalendar]; NSLog(@"----当月日历--%@",calendar); //unsigned已经过期 // unsigned units =NSMonthCalendarUnit|NSDayCalendarUnit|NSYearCalendarUnit; NSCalendarUnitunits=NSCalendarUnitYear|NSCalendarUnitMonth|NSCalendarUnitDay|NSCalendarUnitHour|NSCalendarUnitMinute|NSCalendarUnitSecond ;
NSDateComponents *comp1 = [calendar components:unitsfromDate:date]; NSInteger month = [comp1 month]; NSInteger year = [comp1 year]; NSInteger day = [comp1 day];
NSInteger hour = [comp1 hour]; NSInteger second =[comp1 second]; NSInteger minute = [comp1 minute];
NSLog(@"年:%zi,月:%zi,日:%zi",year,month,day); NSLog(@"时:%zi,分:%zi,秒:%zi",hour,minute,second); //NSDateFormatter实现日期的输出 NSDateFormatter *formatter = [[NSDateFormatter alloc]init]; [formatter setDateStyle:NSDateFormatterFullStyle];//直接输出的话是机器码 //或者是手动设置样式[formattersetDateFormat:@"yyyy-mm-dd"];
NSString *string = [formatter stringFromDate:date]; NSLog(@"string = %@",string);
打印结果: 路径差别在前者的一个是bundle目录下的APPlication (应用里的主要图片,音频资源,xib文件), 后者是data目录下的APPlication 归档时候的文件在Preferences目录下 2015-01-30 22:19:33.645 fjds[2293:208496] -----路径比较 NSBundle </Users/laiyufang/Library/Developer/CoreSimulator/Devices/493E5A96-8066-4EFD-8F69-60F9373DF5E5/data/Containers/Bundle/Application/1892D8BE-1AE4-4353-A27E-82892F9D6C31/fjds.app> (loaded) 2015-01-30 22:19:33.646 fjds[2293:208496] -----路径二 /Users/laiyufang/Library/Developer/CoreSimulator/Devices/493E5A96-8066-4EFD-8F69-60F9373DF5E5/data/Containers/Data/Application/D5B2F5CE-5C36-4922-865B-EFBE0656B15F 2015-01-30 22:19:33.647 fjds[2293:208496] -----日期2015-01-30 14:19:33 +0000 2015-01-30 22:19:33.648 fjds[2293:208496] myDate = 2015-02-01 14:19:33 +0000 2015-01-30 22:19:33.648 fjds[2293:208496] ----当月日历--<_NSCopyOnWriteCalendarWrapper: 0x7fde88cbd460> 2015-01-30 22:19:33.648 fjds[2293:208496] 年:2015,月:1,日:30 2015-01-30 22:19:33.648 fjds[2293:208496] 时:22,分:19,秒:33
2015-01-30 22:19:33.648 fjds[2293:208496] string = Friday, January 30, 2015 |
日期,时间的获取(ios)
最新推荐文章于 2018-03-10 20:59:51 发布