zoukankan      html  css  js  c++  java
  • iOS-获取当前时间的年、月、日、时、分、秒

     //获取当前时间
    02    NSDate *now = [NSDate date];
    03    NSLog(@”now date is: %@”, now);
    04
    05    NSCalendar *calendar = [NSCalendar currentCalendar];
    06    NSUInteger unitFlags = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit;
    07    NSDateComponents *dateComponent = [calendar components:unitFlags fromDate:now];
    08     
    09    int year = [dateComponent year];
    10    int month = [dateComponent month];
    11    int day = [dateComponent day];
    12    int hour = [dateComponent hour];
    13    int minute = [dateComponent minute];
    14    int second = [dateComponent second];
    15
    16    NSLog(@”year is: %d”, year);
    17    NSLog(@”month is: %d”, month);
    18    NSLog(@”day is: %d”, day);
    19    NSLog(@”hour is: %d”, hour);
    20    NSLog(@”minute is: %d”, minute);
    21    NSLog(@”second is: %d”, second);

  • 相关阅读:
    fatal: protocol error: bad line length character: This
    httpd: apr_sockaddr_info_get() failed for bogon
    Go语言函数
    Go语言流程控制
    进制转换
    Go语言运算符
    LeetCode 62. Unique Paths
    LeetCode 61. Rotate List
    asdfasdfasdf
    开发者,别让自己孤独
  • 原文地址:https://www.cnblogs.com/ygm900/p/4473473.html
Copyright © 2011-2022 走看看