只需传入两个日期

/**任意两天相差天数*/

+ (NSInteger)getTheCountOfTwoDaysWithBeginDate:(NSString *)beginDate endDate:(NSString *)endDate{

NSDateFormatter *inputFormatter = [[NSDateFormatter alloc] init];

[inputFormatter setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"en_US"]];

[inputFormatter setDateFormat:@"yyyy-MM-dd"];

NSDate *startD =[inputFormatter dateFromString:beginDate];

NSDate *endD = [inputFormatter dateFromString:endDate];

// 当前日历

NSCalendar *calendar = [NSCalendar currentCalendar];

// 需要对比的时间数据

NSCalendarUnit unit = NSCalendarUnitYear | NSCalendarUnitMonth

| NSCalendarUnitDay;

// 对比时间差

NSDateComponents *dateCom = [calendar components:unit fromDate:startD toDate:endD options:0];

return dateCom.day;

}

iOS计算两天相差多少天相关推荐

  1. oracle计算两日期相差多少秒,分钟,小时,天

    --计算两个时间差相差多少秒 select (sysdate-to_date('2021/12/14 17:00:00','yyyy/mm/dd hh24:mi:ss'))*24*60*60 from ...

  2. ios 计算两个时间相差秒数_Ios中时间差的计算,NSData与NSCalendar(日历)对象

    时间差的计算: 计算过去时间与当前时间的时间差 注意:其中的NSDateFormatter时间格式化类初始化非常消耗性能,如果多次使用,建议定义为全局. NSString *timeStr = @&q ...

  3. ios 计算两个时间相差秒数_iOS NSDate时间换算

    #import "ViewController.h" @interface ViewController () @end @implementation ViewControlle ...

  4. Java计算两日期相差天数源码

    public class MyDate {public int year;public int month;public int day;//1.必须得校验传入参数的合法性// year : 1 &l ...

  5. ios 计算两个时间的时间差

    NSString *time2 = @"2021-06-11 08:05:00"; // 2.将时间转换为date NSDateFormatter *formatter = [[N ...

  6. IOS 计算两个时区之间的时间差

    我们首先使用NSDate来创建两个时间,将两个时间都格式化.转换为字符串格式: NSDateFormatter* dateFormat = [[NSDateFormatter alloc] init] ...

  7. iOS 计算两个日期之间的差值

    NSDateFormatter *dateFomatter = [[NSDateFormatter alloc] init];dateFomatter.dateFormat = @"yyyy ...

  8. oracle日期相减工作日_Oracle 计算两个日期间隔的天数、月数和年数

    在Oracle中计算两个日期间隔的天数.月数和年数: 一.天数: 在Oracle中,两个日期直接相减,便可以得到天数: select to_date('08/06/2015','mm/dd/yyyy' ...

  9. 如何计算俩日期相隔多少年,多少月,多少天或者两时间相差XX年XX月XX日

    假设时开始时间为2015年4月2日,结束时间为2019年4月4月;  需要先熟悉一下时间对象得一些方法,可参考教程http://www.w3school.com.cn/jsref/jsref_obj_ ...

最新文章

  1. 设计模式之简单工厂模式(Simply Factory)摘录
  2. ECLIPSE在线安装SVN
  3. 浅谈tidb事务与MySQL事务之间的区别
  4. 新报告直指3大安全威胁 企业需小心应对
  5. Java线程详解(16)-条件变量
  6. superset 图标调整
  7. HEVC/H265 解码图表,请对照代码看。
  8. python 魔术方法
  9. 【LeetCode笔记】232. 用栈实现队列(Java、栈、队列)
  10. /proc/sys/net/ipv4 详解2
  11. react和nodejs_如何使用NodeJS和React为SaaS构建Stripe Billing入门流程
  12. mysql5.7 glibcxx_3.4.15_Percona Server安装可能出现的问题 version `GLIBCXX_3.4.15' not found ...
  13. Servlet3.0
  14. R语言数据清洗实战——高效list解析方案
  15. java贪吃蛇详细设计,javascript贪吃蛇游戏设计与实现
  16. 如何破解WP7并安装xap文件
  17. 我国云计算中心大盘点
  18. HMTL中隐藏域(type=hidden)
  19. 计算机内存怎么与频率匹配,内存频率,详细教您怎么查看内存条频率
  20. html多行注释如何实现,javascript多行注释如何实现

热门文章

  1. PHP字符串函数substr_replace(替换字符串的子串)
  2. 自动化小工具---秒级倒计时
  3. MyTest.axf section `.text‘ will not fit in region `Flash30‘
  4. Mysql rbo和cbo_oracle的优化——RBO和CBO简介以及optimizer_mode参数说明
  5. (超详细)语音信号处理之特征提取
  6. OPDS书库目录总结(添加OPDS书库目录)
  7. 【GD32F427开发板试用】FreeRTOS移植工程
  8. 可以用什么软件画流程图?看看这几款画流程图软件
  9. [附源码]Python计算机毕业设计房屋中介管理信息系统
  10. 查询多个宅急送已签收单号,并分析出派件时效