美文网首页
获取的NSDate年月日

获取的NSDate年月日

作者: 七里田间的守望者 | 来源:发表于2017-01-07 16:52 被阅读15次
    
    /*
        NSCalendarUnitYear
        NSCalendarUnitMonth
        NSCalendarUnitDay
        NSCalendarUnitHour
        NSCalendarUnitMinute
        NSCalendarUnitSecond
         */
        //当前时间
        NSDate * date = [NSDate date];
        
        NSCalendar *calender = [NSCalendar currentCalendar];
        
        NSInteger year = [calender component:NSCalendarUnitYear fromDate:date];
        NSInteger month = [calender component:NSCalendarUnitMonth fromDate:date];
        NSInteger day = [calender component:NSCalendarUnitDay fromDate:date];
        NSInteger hour = [calender component:NSCalendarUnitHour fromDate:date];
        NSInteger minu = [calender component:NSCalendarUnitMinute fromDate:date];
        NSInteger sec = [calender component:NSCalendarUnitSecond fromDate:date];
        
        NSLog(@"year:%zdmonth:%zdday:%zdhour:%zdminu:%zdsec:%zd",year,month,day,hour,minu,sec);
    

    相关文章

      网友评论

          本文标题:获取的NSDate年月日

          本文链接:https://www.haomeiwen.com/subject/lzufbttx.html