C 语言实例 - 计算两个时间段的差值
C 语言实例 C 语言实例
计算两个时间段的差值。
实例
#include <stdio.h> struct TIME
{
int seconds;
int minutes;
int hours;
};
void differenceBetweenTimePeriod(struct TIME t1, struct TIME t2, struct TIME *diff); int main()
{
struct TIME startTime, stopTime, diff; printf("输入开始时间: \n");
printf("输入小时、分钟、秒:");
scanf("%d %d %d", &startTime.hours, &startTime.minutes, &startTime.seconds); printf("输入停止时间: \n");
printf("输入小时、分钟、秒: ");
scanf("%d %d %d", &stopTime.hours, &stopTime.minutes, &stopTime.seconds); // 计算差值
differenceBetweenTimePeriod(startTime, stopTime, &diff); printf("\n差值: %d:%d:%d - ", startTime.hours, startTime.minutes, startTime.seconds);
printf("%d:%d:%d ", stopTime.hours, stopTime.minutes, stopTime.seconds);
printf("= %d:%d:%d\n", diff.hours, diff.minutes, diff.seconds); return ;
} void differenceBetweenTimePeriod(struct TIME start, struct TIME stop, struct TIME *diff)
{
if(stop.seconds > start.seconds){
--start.minutes;
start.seconds += ;
} diff->seconds = start.seconds - stop.seconds;
if(stop.minutes > start.minutes){
--start.hours;
start.minutes += ;
} diff->minutes = start.minutes - stop.minutes;
diff->hours = start.hours - stop.hours;
}
输出结果为:
输入开始时间:
输入小时、分钟、秒:
输入停止时间:
输入小时、分钟、秒: 差值: :: - :: = ::

C 语言实例 - 计算两个时间段的差值的更多相关文章

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

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

  2. 【HANA系列】SAP HANA SQL计算两个日期的差值

    公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[HANA系列]SAP HANA SQL计算两个 ...

  3. javascript 计算两个日期的差值

    代码 Typescript版 /** * TimeSpan just like the class TimpSpan in C# ,represent the time difference * @c ...

  4. 【峰回路转】Excel技巧百例 08.计算两个日期的差值

    在Excel中假设高速计算两个日期之间的差? 比如A日期为:2012/3/12   B日期为:2015/7/29  那么这两个日期之间差几年,差几个月.差多少天? 我们使用DateDif 函数来处理. ...

  5. js计算两个日期的差值

    // 获取两个比较值的毫秒数var postman_confirmtime_ms = Date.parse(new Date(data.postman_confirmtime.replace(/-/g ...

  6. Oracle 计算两个时间的差值

    有两个日期数据START_DATE,END_DATE,欲得到这两个日期的时间差(以天,小时,分钟,秒,毫秒):天:ROUND(TO_NUMBER(END_DATE - START_DATE))小时:R ...

  7. moment实现计算两个时间的差值

    var m1 = moment('2018-08-14 11:00:00'), m2 = moment('2018-08-14 12:10:00'); console.log(m1)console.l ...

  8. C 语言实例 - 求两数最小公倍数

    C 语言实例 - 求两数最小公倍数 用户输入两个数,其这两个数的最小公倍数. 实例 - 使用 while 和 if #include <stdio.h> int main() { int ...

  9. PHP计算两个时间段是否有交集(边界重叠不算)

    优化前的版本: /** * PHP计算两个时间段是否有交集(边界重叠不算) * * @param string $beginTime1 开始时间1 * @param string $endTime1 ...

随机推荐

  1. signal函数理解或者void (*signal(int signum,void(*handler)(int)))(int)理解

    把void (*signal(int signum,void(*handler)(int)))(int)分成两部分: typedef void (*sighandler_t)(int); sighan ...

  2. JS获取当前页面的URL

    如果获取“当前”域名 host = window.location.host; url=document.domain; url = window.location.href; 取得完整url路径: ...

  3. LightOJ1341 Aladdin and the Flying Carpet —— 唯一分解定理

    题目链接:https://vjudge.net/problem/LightOJ-1341 1341 - Aladdin and the Flying Carpet    PDF (English) S ...

  4. poj3461 Oulipo —— KMP

    题目链接:http://poj.org/problem?id=3461 代码如下: #include<cstdio>//poj 3461 kmp #include<cstring&g ...

  5. HDU5968 异或密码 —— 二分 + 边界的细节处理

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5968 异或密码 Time Limit: 2000/1000 MS (Java/Others)    M ...

  6. CSU - 1529 Equator —— DP 最大连续和子序列

    题目链接:http://acm.csu.edu.cn/csuoj/problemset/problem?pid=1529 题解: 一个加强版的最大连续和子序列,序列可以从末尾元素转到首元素. 分两种情 ...

  7. Appium——WebDriverException: Message: A new session could not be created.

    每次启动完一次脚本再次启动的时候会报这个错误,会话没有被创建 查看了下Appium日志: 查看下设备是否准备好,我用的是模拟器,就cmd下查看下设备: 可以看到设备掉线了... 好吧,重启下设备 脚本 ...

  8. Appium java 环境配置

    一.安装node.js 下载地址:http://pan.baidu.com/s/1qYyNDm8 点击安装,next下一步就ok. 安装完成,命令行输入:npm 这样显示的话就ok了.  二.下载Ap ...

  9. Java 出现“Illegal key size”错误的解决方案

    用AES加密时出现"java.security.InvalidKeyException: Illegal key size"异常. 如果密钥大于128, 会抛出上述异常.因为密钥长 ...

  10. complex brain network

    Organization, development and function of complex brain networks The Brain as a Complex System: Usin ...