//创建当前日期
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:];
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

日期字符串转换 and 两个日期相减的更多相关文章

  1. libs/tools.js stringToDate dateToString 日期字符串转换函数

    libs/tools.js stringToDate dateToString 日期字符串转换函数 import { stringToDate } from '@/libs/tools.js'   e ...

  2. 表单中的日期 字符串和Javabean中的日期类型的属性自动转换

    搞了一上午的bug最终还是因为自己springMVC的注解不熟悉的原因,特记录. 在实际操作中经常会碰到表单中的日期 字符串和Javabean中的日期类型的属性自动转换, 而springMVC默认不支 ...

  3. oracle 两个时间相减

    oracle 两个时间相减默认的是天数 oracle 两个时间相减默认的是天数*24 为相差的小时数 oracle 两个时间相减默认的是天数*24*60 为相差的分钟数 oracle 两个时间相减默认 ...

  4. C#两个时间相减

    原文地址:http://www.jb51.net/article/60177.htm using System; using System.Collections.Generic; using Sys ...

  5. C#实现两个时间相减的方法

    脚本之家看到的,关于两个时间差值的获取 http://www.jb51.net/article/60177.htm using System; using System.Collections.Gen ...

  6. mssql sqlserver 使用sql脚本实现相邻两条数据相减的方法分享

    摘要: 下文讲述使用sql脚本实现相邻两条数据相减的方法,如下所示: 实验环境:sql server 2008 R2 实现思路: 1.使用cte表达式,对当前表进行重新编号 2.使用左连接对 表达式 ...

  7. SQL to_char,to_date日期字符串转换问题

    1.转换函数 与date操作关系最大的就是两个转换函数:to_date(),to_char() to_date() 作用将字符类型按一定格式转化为日期类型: 具体用法:to_date('2004-11 ...

  8. mysql将日期字符串转换

    举个例子: 给定字符串为07/31/2018,想要把格式转换成20180731 需要用到以下两个函数: date_format(date,’%Y-%m-%d’) ————–>oracle中的to ...

  9. C# 字符串string类型转换成DateTime类型 或者 string转换成DateTime?(字符串转换成可空日期类型)

    在c#中,string类型转换成DateTime类型是经常用到的,作为基本的知识,这里在此做个小结.一般来说可以使用多种方法进行转换,最常用的就是使用Convert.ToDateTime(string ...

随机推荐

  1. C#方法封装与重构

    C#作为一个完全面向对象的语言,有个特性很重要但是往往会不重视,而不重视的结果就会造成代码杂乱难以解读.维护.这个特性就是封装.      这里不是大谈C#的封装,我只讲一个,关于方法封装的一些问题. ...

  2. DIV+CSS规范命名大全集合

    (从已经死了一次又一次终于挂掉的百度空间人工抢救出来的,发表日期 2014-06-19)   网页制作中规范使用DIV+CSS命名规则,可以改善优化功效特别是团队合作时候可以提供合作制作效率,具体DI ...

  3. github 多帐户使用

    同一台电脑有2个github账号?咋办 比如一个公司账号一个个人账号. 私人账号如下: 邮箱example@126.com 账号:example 公司工作账号如下: work@xx.com 账号:my ...

  4. 解决Unable to connect to a repository at URL 禁止访问 (forbidden)

    连接SVN报如下错误. Unable to connect to a repository at URL 禁止访问 (forbidden) 1.         右键点击本地副本,TortoiseSV ...

  5. App Submission Issues

    查看原文: http://leancodingnow.com/app-submission-issues/ I bet many iOS developers are busy submitting ...

  6. Slony-I 文摘

    http://www.onlamp.com/pub/a/onlamp/2004/11/18/slony.html  我特别喜欢这篇文章,就进行了转载和翻译. Introducing Slony by  ...

  7. 使用.net(C#)发送邮件学习手册(带成功案例)

    使用.net(C#)发送邮件学习手册(带成功案例) 1.了解发送邮件的三种方式 2.实例介绍使用client.DeliveryMethod = System.Net.Mail.SmtpDelivery ...

  8. 搭建Spring + SpringMVC + Mybatis框架之三(整合Spring、Mybatis和Spring MVC)

    整合Spring和SpringMVC 之前已经整合了spring和mybatis,现在在此基础上整合SSM. 项目目录: 思路:SpringMVC的配置文件独立,然后在web.xml中配置整合. (1 ...

  9. 【C语言】模拟实现库函数strcat函数

    //模拟实现库函数strcat函数 #include <stdio.h> #include <string.h> #include <assert.h> char ...

  10. 关于CQRS(老外经典好文)

    CQRS means Command Query Responsibility Segregation. Many people think that CQRS is an entire archit ...