zoukankan      html  css  js  c++  java
  • 取得NSDate实例各个字段的数字

    代码:

     1     NSDate *now = [NSDate date];
     2     NSCalendar *calendar = [NSCalendar currentCalendar];
     3     
     4     //获取年、月、日、时、分、秒等组件
     5     NSDateComponents *dateComponents = [calendar components:NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay | NSCalendarUnitHour | NSCalendarUnitMinute | NSCalendarUnitSecond fromDate:now];
     6     NSLog(@"[%d]", dateComponents.year);    //
     7     NSLog(@"[%d]", dateComponents.month);   //
     8     NSLog(@"[%d]", dateComponents.day);     //
     9     NSLog(@"[%d]", dateComponents.hour);    //
    10     NSLog(@"[%d]", dateComponents.minute);  //
    11     NSLog(@"[%d]", dateComponents.second);  //
  • 相关阅读:
    合并两个有序链表
    有效括号方法二
    有效括号
    es6 中的模块化
    XMLHttpRequest 对象
    AST
    php读写文件方式
    vue开发中遇到的问题
    sublime操作
    cmd命令
  • 原文地址:https://www.cnblogs.com/cmembd/p/3855834.html
Copyright © 2011-2022 走看看