zoukankan      html  css  js  c++  java
  • 日期字符串转换 and 两个日期相减

        //创建当前日期
        NSDate *date = [NSDate date];
        //创建日期格式类
        NSDateFormatter *dateFormat = [[NSDateFormatter alloc]init];
        //设置日期格式
        [dateFormat setDateFormat:@"yyyy/MM/dd HH:mm:ss"];
        //获取招聘信息的创建日期
        NSDate *createDate =[dateFormat dateFromString:_recruit.createTime];
        
        NSLog(@"recruit.createTime==》%@ date==>:%@ - createDate:%@",recruit.createTime,date,createDate);
        
        NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
        unsigned int unitFlags = NSDayCalendarUnit;
        NSDateComponents *comps = [gregorian components:unitFlags fromDate:createDate  toDate:date  options:0];
        int days = [comps day];
        NSLog(@"天数===%d",days);

    打印:

    recruit.createTime==2014/5/7 14:57:49 date==>2014-05-15 07:45:34 +0000 - createDate:2014-05-07 06:57:49 +0000

  • 相关阅读:
    hive参数配置及任务优化
    python基础篇_002_基础数据类型
    python基础篇_001_初识Python
    Java 修饰符
    Java 构造代码块
    Java static 关键字
    Java 继承
    37 自定义异常
    36 异常
    35 异常
  • 原文地址:https://www.cnblogs.com/hw140430/p/3730153.html
Copyright © 2011-2022 走看看