UIButton * nameButton = [UIButton buttonWithType:UIButtonTypeCustom];

nameButton.frame = CGRectMake(0, 200, self.view.frame.size.width, 100);

nameButton.backgroundColor = [UIColor orangeColor];

[self.view addSubview:nameButton];

NSCalendar *calendar = [NSCalendar currentCalendar];

NSDate *starDate = [NSDate dateWithTimeIntervalSince1970:1513142700];//开始时间

NSDate *endDate = [NSDate dateWithTimeIntervalSince1970:1513146300];//结束时间

unsigned int unitFlags = NSCalendarUnitYear| NSCalendarUnitMonth | NSCalendarUnitDay | NSCalendarUnitHour | NSCalendarUnitMinute | NSCalendarUnitSecond ;

NSDateComponents *d = [calendar components:unitFlags fromDate:starDate toDate:endDate options:0];

[nameButton setTitle:[NSString stringWithFormat:@"%ld小时%ld分%ld秒", (long)[d hour], (long)[d minute], (long)[d second]] forState:0];

iOS-----------计算两个时间的时间差的更多相关文章

  1. iOS计算两个时间的时间差

    + (long)calculteHourL:(NSDate *)endDate startDate:(NSDate *)startDate { NSCalendar *cal = [NSCalenda ...

  2. C#计算两个时间的时间差,精确到年月日时分秒

    喏,计算两个时间的时间差,精确到年月日时分秒 看起来比较笨的方法了,不知道有没有改进 DateTime d1 = new DateTime(2016, 4, 1, 0, 0, 0); DateTime ...

  3. c# 计算两个时间的时间差

    //计算2个日期之间的天数差 DateTime dt1 = Convert.ToDateTime("2007-8-1"); DateTime dt2 = Convert.ToDat ...

  4. C#两个时间的时间差的方法

    今天遇到一问题,计算两个时间的时间差,看网上的写法较为复杂,找到个简单点的,记录下作为自己的总结. 关键函数: DateTime.Subtract 函数解释: 从此实例中减去指定的日期和时间,返回一个 ...

  5. mysql中计算两个日期的时间差函数TIMESTAMPDIFF用法

    mysql中计算两个日期的时间差函数TIMESTAMPDIFF用法: 语法: TIMESTAMPDIFF(interval,datetime_expr1,datetime_expr2) 说明: 返回日 ...

  6. Python datetime库计算两个时间点之间的分钟(秒、天)数

    计算两个时间点之间的分钟数 import datetime def minNums(startTime, endTime): '''计算两个时间点之间的分钟数''' # 处理格式,加上秒位 start ...

  7. JS比较两个时间的时间差

    /** * 比较两个时间的时间差 * @param startTime 开始时间 * @param endTime 结束时间 * @demo compareTime(new Date('2019-12 ...

  8. IOS 计算两个经纬度之间的距离

    IOS 计算两个经纬度之间的距离 一 丶 -(double)distanceBetweenOrderBy:(double) lat1 :(double) lat2 :(double) lng1 :(d ...

  9. C#计算两个时间年份月份差

    C#计算两个时间年份月份差 https://blog.csdn.net/u011127019/article/details/79142612

  10. oracle计算两个时间的差值(XX天XX时XX分XX秒)

    在工作中需要计算两个时间的差值,结束时间 - 开始时间,又不想在js里写function,也不想在java里去计算,干脆就在数据库做了一个函数来计算两个时间的差值.格式为XX天XX时XX分XX秒: 上 ...

随机推荐

  1. Javascript高级编程学习笔记(57)—— 事件(1)事件流

    事件 JS与HTML的交互是通过事件实现的 而事件指的就是:文档或浏览器窗口特定的交互瞬间 可以通过侦听器来预定事件,以便在事件发生时执行相应的代码 这种模式也是设计模式中的观察者模式 事件流 有了事 ...

  2. 吴恩达机器学习笔记56-多元高斯分布及其在误差检测中的应用(Multivariate Gaussian Distribution & Anomaly Detection using the Multivariate Gaussian Distribution)

    一.多元高斯分布简介 假使我们有两个相关的特征,而且这两个特征的值域范围比较宽,这种情况下,一般的高斯分布模型可能不能很好地识别异常数据.其原因在于,一般的高斯分布模型尝试的是去同时抓住两个特征的偏差 ...

  3. 吴恩达机器学习笔记52-异常检测的问题动机与高斯分布(Problem Motivation of Anomaly Detection& Gaussian Distribution)

    一.问题动机 异常检测(Anomaly detection)问题是机器学习算法的一个常见应用.这种算法的一个有趣之处在于:它虽然主要用于非监督学习问题,但从某些角度看,它又类似于一些监督学习问题. 给 ...

  4. [Java]LeetCode690. 员工的重要性 | Employee Importance

    You are given a data structure of employee information, which includes the employee's unique id, his ...

  5. [Swift]LeetCode834. 树中距离之和 | Sum of Distances in Tree

    An undirected, connected tree with N nodes labelled 0...N-1 and N-1 edges are given. The ith edge co ...

  6. Primitive Assembly

    I found something in the Specification of OpenGL Version 4.6 (Core Profile): The output of Vertex Sh ...

  7. Python Matplotlib.pyplot plt 中文显示

    话不多说,上代码 # -*- coding: UTF-8 -*- import matplotlib.pyplot as plt from matplotlib.font_manager import ...

  8. 安装需要的第三方库时,命令行输入pip提示不是内部或外部命令

    简介 在做Python开发时,安装需要的第三方库时,大多数人喜欢选择在命令行用pip进行安装. 然而有时敲入pip命令会提示‘pip’不是内部或外部命令..如图: 解决办法 1.在python安装目录 ...

  9. 一步一步教你如何用Python做词云

    前言 在大数据时代,你竟然会在网上看到的词云,例如这样的. 看到之后你是什么感觉?想不想自己做一个? 如果你的答案是正确的,那就不要拖延了,现在我们就开始,做一个词云分析图,Python是一个当下很流 ...

  10. windows部署MongoDB

    打开MongoDb下载页面,分别下载Community Server和Compass,注意在安装Community Server时可以勾选同时安装Compass,但会比较慢,所以建议两个分开下载安装. ...