发布网友 发布时间:2022-04-23 22:32
共1个回答
热心网友 时间:2023-10-12 07:03
#include <iostream>
#include <time.h>
using namespace std;
int main()
{
char buf[9] = { 0 };
time_t t = time(0);
auto current = localtime(&t);
sprintf(buf, "%02d:%02d:%02d", current->tm_hour, current->tm_min, current->tm_sec);
cout << buf << endl;
tm* lt = localtime(&t);
cout << "请输入时间(格式 h:m:s):";
int hour, min, sec;
scanf("%d:%d:%d", &hour, &min, &sec);
lt->tm_hour = hour;
lt->tm_min = min;
lt->tm_sec = sec;
time_t t1 = mktime(lt);
int ret = difftime(t, t1);
cout << "时间差:" << ret << "秒";
return 0;
}