我正在try 一个图书借阅系统,它可以告诉用户他们必须归还图书的日期.因为我必须用这些数据来判断借款时间是否超过了限额.我try 使用两个tm struct .
struct tm *Olddate;
struct tm *Newdate;
我在一个这样的 struct 上加了几天
Newdate->tm_mday += 7;
当我试着打印出两个不同的 struct 时,输出在某种程度上是相同的.
printf("Current local time and date: %s", asctime(Olddate));
printf("Current new time and date: %s", asctime(Newdate));
输出:
Current local time and date: Tue May 17 21:37:16 2022
New time and date: Tue May 17 21:37:16 2022
最小可重复性示例:
#include <stdio.h>
#include <time.h>
int main () {
time_t rawtime;
struct tm *Olddate;
struct tm *Newdate;
time( &rawtime );
Olddate = localtime(&rawtime);
Newdate = localtime(&rawtime);
Newdate->tm_mday += 7;
printf("Current local time and date: %s", asctime(Olddate));
printf("New time and date: %s", asctime(Newdate));
return 0;
}