zoukankan      html  css  js  c++  java
  • OC中显示当前时间

       NSDate *date=[NSDate date];

            //创建了一个NSDATE对象 是一个0000时区的时间并不是我们当前的时间

            

      //获取当前时间

            NSTimeZone *timeZone=[NSTimeZone systemTimeZone];//返回一个系统的时区

            NSInteger interval=[timeZone secondsFromGMTForDate:date];

            //0时区是date 相差interval秒

            NSDate * localdate=[date dateByAddingTimeInterval:interval];

            NSLog(@"%@",localdate);

            //格式化输出

            NSDateFormatter *f=[NSDateFormatter new];

            f.dateFormat=@"yyyy年MM月dd日 HH时mm分ss秒";

            NSString * strdate=[f stringFromDate:localdate];

            NSLog(@"%@",strdate);

      NSCalendar * calendar  = [NSCalendar currentCalendar];//当前日历

      //  

      NSDateComponents * component  = [calendar components:NSCalendarUnitHour fromDate:date toDate:datelocal options:0];

        

        NSLog(@"%ld",component.hour);

    //    NSInteger year = [calendar component:NSCalendarUnitMonth fromDate:date];

        

    //    NSDateComponents * component = [calendar components:NSCalendarUnitMonth|NSCalendarUnitDay fromDate:date];

      

  • 相关阅读:
    Http协议(一)基础知识
    Redis问题汇总
    Sql Server存储过程传递XML参数
    C# Redis
    Task的异常捕获和处理方法
    Entity Framework教程
    WebBrowser 弹窗体关闭原理
    C# 虹软SDK视频人脸识别和注册
    C#性能优化:延迟初始化Lazy
    DZ 特殊主题简单开发教程
  • 原文地址:https://www.cnblogs.com/DreamLinku/p/5385042.html
Copyright © 2011-2022 走看看