Linux下获取当前时间到1970年之前某年份的秒数的C代码实现

一、问题描述 在Linux下编写一C程序,用于获取当前时间到1970年之前某年份的秒数。

二、C代码实现

/** 版权所有 (C)2015, Zhou Zhaoxiong。** 文件名称:GetSecNumBetweenTwoYear.c* 文件标识:无* 内容摘要:获取当前时间到1970年之前某时间的秒数* 其它说明:无* 当前版本:V1.0* 作 者:Zhou Zhaoxiong* 完成日期:20150211**/typedef unsigned short int UINT16;typedef signed intINT32;typedef unsigned intUINT32;UINT32 GetSecNumBetweenTwoYear(UINT16 iFirstYear, UINT16 iSecondYear);INT32 main();/** 功能描述:主函数* 输入参数:无* 输出参数:无* 返 回 值:无* 其它说明:无* 修改日期版本号修改人修改内容* ——————————————————————-* 20150211V1.0Zhou Zhaoxiong创建*/INT32 main(){}/功能描述: 计算任意两年之间的秒数* 输入参数: iFirstYear-减数iSecondYear-被减数* 输出参数: 无* 返 回 值: 秒数* 其它说明: 无* 修改日期版本号修改人修改内容* ——————————————————————–* 20150211V1.0Zhou Zhaoxiong创建*/UINT32 GetSecNumBetweenTwoYear(UINT16 iFirstYear, UINT16 iSecondYear){}

三、makefile文件内容

GetSecNumBetweenTwoYear : GetSecNumBetweenTwoYear.cgcc -c -g GetSecNumBetweenTwoYear.cgcc -g -o release/GetSecNumBetweenTwoYear GetSecNumBetweenTwoYear.orm *.o

四、程序说明 (1) 在Linux下,有一个函数time用户获取时间,但时间的起点是从1970年开始的,因此本程序获取的时间分为两段:输入时间到1970年的时间和1970年到当前的时间。输入时间到1970年的时间用自编的函数获取,1970年到当前的时间用time(0)获取。 (2) 打印获取到的秒数的时候,要用“%u”格式;如果采用“%d”格式,则会出现整型值溢出的情况,打印出负值。

五、程序运行结果 运行“make”命令之后,转到“release”目录下,执行“GetSecNumBetweenTwoYear”,结果如下: (1) 正常用例

release> GetSecNumBetweenTwoYearPlease input a year before 1970: 1900The total is: 2208988800The total now is: 3632613008release> GetSecNumBetweenTwoYearPlease input a year before 1970: 1910The total is: 1893456000The total now is: 3317080221

(2) 异常用例

release> GetSecNumBetweenTwoYearPlease input a : 1990The , please check!

本人微信公众号:zhouzxi,,请扫描以下二维码:

人生不如意十之八-九,与其诅咒黑暗,倒不如在生命中点燃一盏灯

Linux下获取当前时间到1970年之前某年份的秒数的C代码实现

相关文章:

你感兴趣的文章:

标签云: