zoukankan      html  css  js  c++  java
  • [ios]获取时间 【转】

    1.

    NSDate *date = [NSDate date];  

    NSCalendar *calendar = [NSCalendar currentCalendar];  

    NSDateComponents *comps;  

    //年月日  

    comps = [calendar components:(NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit) fromDate:date];  

    NSInteger year = [comps year];  

    NSInteger rmonth = [comps month];  

    NSInteger day = [comps day];  

    //时分秒  

    comps = [calendar components:(NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit) fromDate:date];  

    NSInteger hour = [comps hour];  

    NSInteger minute = [comps minute];  

    NSInteger second = [comps second];  

    //星期几  

    comps = [calendar components:(NSWeekCalendarUnit | NSWeekdayCalendarUnit | NSWeekdayOrdinalCalendarUnit) fromDate:date];  

    NSInteger week = [comps week];//今年的第几周  

    NSInteger weekdayOrdinal = [comps weekdayOrdinal];//这个月的第几周  

    NSInteger weekday = [comps weekday];//星期几(周日是“1”,周一是“2”) 

        NSDateFormatter *outputFormatter = [[[NSDateFormatter allocinitautorelease]; 

        [outputFormatter setLocale:[NSLocale currentLocale]];

        [outputFormatter setDateFormat:@"yyyyMMdd HHmmss"];

        NSString *str = [outputFormatter stringFromDate:inputDate];

        NSLog(@"testDate:%@", str);

  • 相关阅读:
    ASP.NET MVC 部分视图
    IIS7.5安全配置研究
    微信公众号抢现金红包活动的核心代码分析(asp.net C#)
    [Android] hid设备按键流程简述
    [Android] AudioTrack::start
    [Android] createTrack_l
    [Android] 输入系统(三):加载按键映射
    [Android] 获取音频输出getOutput
    [Android] AudioTrack实例
    [Android] 输入系统(二)
  • 原文地址:https://www.cnblogs.com/jinjiantong/p/2992616.html
Copyright © 2011-2022 走看看