Chinaunix首页 | 论坛 | 博客
  • 博客访问: 91015
  • 博文数量: 22
  • 博客积分: 486
  • 博客等级: 下士
  • 技术积分: 262
  • 用 户 组: 普通用户
  • 注册时间: 2012-03-07 19:26
文章分类

全部博文(22)

文章存档

2012年(22)

我的朋友

分类: 嵌入式

2012-06-27 16:15:22


点击(此处)折叠或打开

  1. - (IBAction)reslut_value:(id)sender
  2. {
  3.     
  4.     /*分别表示年、月、日、时、分、秒*/
  5.     NSInteger unitFlags = NSYearCalendarUnit |
  6.     NSMonthCalendarUnit |
  7.     NSDayCalendarUnit |
  8.     NSWeekCalendarUnit |
  9.     NSHourCalendarUnit|
  10.     NSMinuteCalendarUnit |
  11.     NSSecondCalendarUnit;
  12.     //********************
  13.     
  14.     NSDate *date = [NSDate date];
  15.     
  16.     NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
  17.     NSDateComponents *comps;
  18.     comps = [calendar components: unitFlags fromDate:date];
  19.     
  20.     /*分别取出年、月、日、时、分、秒*/
  21.     int year = [comps year];
  22.     int month = [comps month];
  23.     int day = [comps day];
  24.     int hour = [comps hour];
  25.     int min = [comps minute];
  26.     int sec = [comps second];
  27.     //************************
  28.     
  29.     /*打印输出time*/
  30.     NSLog(@"time:%i-%i-%i %i:%i:%i\n",year,month,day,hour,min,sec);
  31.     
  32. }


  33. //输出结果为: Calculator[2233:f803] time:2012-6-27 16:13:23

阅读(510) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~