root@wisdom-B250-HD3:/tmp# cat 151623.c
/*************************************************************************
> File Name: 151623.c
> Author:
> Mail:
> Created Time: 2019年09月18日 星期三 15时16分28秒
************************************************************************/
#include <stdio.h>
#include <time.h>
int main(void)
{
struct tm *tblock;
time_t t_now = time(NULL);
time_t t_max = 0x7fffffff;
time_t t_tmp = t_max - t_now;
printf("the difference is %f seconds\n", difftime(t_max, t_now));
tblock = localtime(&t_tmp);
printf("%s\n", asctime(tblock));
return 0;
}
root@wisdom-B250-HD3:/tmp# ./a.out
the difference is 578690918.000000 seconds
Wed May 4 04:28:38 1988
root@wisdom-B250-HD3:/tmp#
雨巷
最新推荐文章于 2025-08-18 10:33:50 发布
本文介绍了一个使用C语言处理时间差并输出本地时间的例子。通过调用time.h库中的函数,如time()和localtime(),展示了如何计算两个时间点之间的差值,并将时间结构体转换为可读的字符串格式。

2625

被折叠的 条评论
为什么被折叠?



