zoukankan      html  css  js  c++  java
  • NSDate

    NSDate *date = [NSDate date];//这个是NSDate类型的日期,所要获取的年月日都放在这里;

        

            NSCalendar *cal = [NSCalendar currentCalendar];

            unsigned int unitFlags = NSYearCalendarUnit|NSMonthCalendarUnit|

                                        NSDayCalendarUnit;//这句是说你要获取日期的元素有哪些。获取年就要写NSYearCalendarUnit,获取小时就要写NSHourCalendarUnit,中间用|隔开;

            

            NSDateComponents *d = [cal components:unitFlags fromDate:date];//把要从date中获取的unitFlags标示的日期元素存放在NSDateComponents类型的d里面;

    //然后就可以从d中获取具体的年月日了;

            NSInteger year = [d year];

            NSInteger month = [d month];

            NSInteger day  =  [d day];

          

            NSLog(@"%ld",year);

            NSLog(@"%ld",month);

            NSLog(@"%ld",day);

  • 相关阅读:
    ambari
    linux常用命令
    scala新版本学习(3)
    Spring中的AOP
    Spring中的Bean
    Spring的基本应用(1):依赖以及控制反转
    Scala新版本学习(2):
    python之time模块
    python之编码与解码
    爬虫之re数据提取的使用
  • 原文地址:https://www.cnblogs.com/GYCocoa/p/5510971.html
Copyright © 2011-2022 走看看