- UID
- 1
- 精华
- 积分
- 76361
- 威望
- 点
- 宅币
- 个
- 贡献
- 次
- 宅之契约
- 份
- 最后登录
- 1970-1-1
- 在线时间
- 小时
|
这个和那个VB的差不多。这是个控制台程序,用法如下。 D:\C_Proj\TimeCalc\Release>TimeCalc
USAGE:
TimeCalc <HH:MM:SS> <operator> <HH:MM:SS>
Operator can be + - * / % & | ^ << >> BIN下载:
TimeCalc.exe
(44 KB, 下载次数: 0, 售价: 1 个宅币)
SRC下载:
TimeCalc.7z
(18.04 KB, 下载次数: 0, 售价: 10 个宅币)
代码在此。VC6编译通过。- //=============================================================================
- //TimeCalc:
- //进行HH:MM:SS格式的时间的加减乘除等运算。
- //作者:0xAA55
- //论坛:[url]http://www.0xaa55.com/[/url]
- //版权所有(C) 2013-2014 技术宅的结界
- //请保留原作者信息,否则视为侵权
- //-----------------------------------------------------------------------------
- #include<stdio.h>
- #include<time.h>
- #define TC_SecondsPerMinute 60
- #define TC_MinutesPerHour 60
- #define TC_HoursPerDay 24
- #define TC_SecondsPerHour (TC_SecondsPerMinute*TC_MinutesPerHour)
- #define TC_SecondsPerDay (TC_SecondsPerMinute*TC_MinutesPerHour*TC_HoursPerDay)
- //=============================================================================
- //TimeToSeconds:
- //将H:M:S表示时间转换为秒
- //-----------------------------------------------------------------------------
- #define TimeToSeconds(h,m,s) s+m*TC_SecondsPerMinute+h*TC_SecondsPerHour
- //=============================================================================
- //SecondsToTime:
- //将秒转换为H:M:S表示时间
- //-----------------------------------------------------------------------------
- void SecondsToTime(time_t Time,unsigned*puHours,unsigned*puMinutes,unsigned*puSeconds)
- {
- *puHours= (Time / TC_SecondsPerHour),
- *puMinutes=(Time / TC_SecondsPerMinute) % TC_MinutesPerHour,
- *puSeconds=(Time % TC_SecondsPerMinute);
- }
- //=============================================================================
- //ParseTimeString:
- //从H:M:S格式的字符串提取H、M、S的值
- //返回解析的数值个数
- //-----------------------------------------------------------------------------
- #define ParseTimeString(str,ph,pm,ps) \
- sscanf(str,"%u:%u:%u",ph,pm,ps)
- void Usage()
- {
- fputs(
- "USAGE:\n"
- "TimeCalc <HH:MM:SS> <operator> <HH:MM:SS>\n"
- "Operator can be + - * / % & | ^ << >>\n",stderr);
- }
- int main(int argc,char**argv)
- {
- time_t
- tTime1,
- tTime2,
- tTimeResult;
- unsigned
- uHours1,
- uMinutes1,
- uSeconds1;
- unsigned
- uHours2,
- uMinutes2,
- uSeconds2;
- unsigned
- uHoursResult,
- uMinutesResult,
- uSecondsResult;
- if(argc<4)
- {
- Usage();
- return 1;
- }
- //分析输入的字符串
- if(ParseTimeString(argv[1],&uHours1,&uMinutes1,&uSeconds1)!=3)
- {
- Usage();
- return 1;
- }
- if(ParseTimeString(argv[3],&uHours2,&uMinutes2,&uSeconds2)!=3)
- {
- Usage();
- return 1;
- }
- //换算成秒
- tTime1=TimeToSeconds(uHours1,uMinutes1,uSeconds1);
- tTime2=TimeToSeconds(uHours2,uMinutes2,uSeconds2);
- //判断运算符
- if(!strcmp(argv[2],"+"))
- {
- tTimeResult=tTime1+tTime2;
- }else
- if(!strcmp(argv[2],"-"))
- {
- tTimeResult=tTime1-tTime2;
- }else
- if(!strcmp(argv[2],"*"))
- {
- tTimeResult=tTime1*tTime2;
- }else
- if(!strcmp(argv[2],"/"))
- {
- tTimeResult=tTime1/tTime2;
- }else
- if(!strcmp(argv[2],"%"))
- {
- tTimeResult=tTime1%tTime2;
- }else
- if(!strcmp(argv[2],"&"))
- {
- tTimeResult=tTime1&tTime2;
- }else
- if(!strcmp(argv[2],"|"))
- {
- tTimeResult=tTime1|tTime2;
- }else
- if(!strcmp(argv[2],"^"))
- {
- tTimeResult=tTime1^tTime2;
- }else
- if(!strcmp(argv[2],"<<"))
- {
- tTimeResult=tTime1<<tTime2;
- }else
- if(!strcmp(argv[2],">>"))
- {
- tTimeResult=tTime1>>tTime2;
- }
- //转换成H:M:S的格式
- SecondsToTime(tTimeResult,&uHoursResult,&uMinutesResult,&uSecondsResult);
- //打印
- printf("%u:%u:%u\n",uHoursResult,uMinutesResult,uSecondsResult);
-
- //结束
- return 0;
- }
复制代码 |
|