发布网友 发布时间:2022-04-20 16:33
共5个回答
热心网友 时间:2023-07-11 16:31
#include <stdio.h>;
#include <time.h>;
time_t scanf_time(char * timestr)
{
struct tm t;
if(!timestr) return 0;
memset(&t, 0, sizeof(t));
sscanf(timestr, "%02d%02d%02d %02d:%02d:%02d",
&(t.tm_mday), &(t.tm_mon), &(t.tm_year),
&(t.tm_hour), &(t.tm_min), &(t.tm_sec));
t.tm_year += 100;
t.tm_mon -=1;
return mktime(&t);
}
int main(int argc, char *argv[])
{
time_t x = 0;
time_t y = 0;
x = scanf_time("160312 00:00:00");
y = time(NULL);
if(x>y){
//0=1970-00-01 08:00:00
struct tm t;
memcpy(&t, localtime(&x), sizeof(struct tm));
printf("\n%d年-%d月-%d日\t%d时:%d分:%d秒\n", t.tm_year + 1900, t.tm_mon+1, t.tm_mday, t.tm_hour, t.tm_min, t.tm_sec);
memcpy(&t, localtime(&y), sizeof(struct tm));
printf("\n%d年-%d月-%d日\t%d时:%d分:%d秒\n", t.tm_year + 1900, t.tm_mon+1, t.tm_mday, t.tm_hour, t.tm_min, t.tm_sec);
time_t result = x - y;
memcpy(&t, localtime(&result), sizeof(struct tm));
printf("\n%d年-%d月-%d日\t%d时:%d分:%d秒\n", t.tm_year -70, t.tm_mon, t.tm_mday-1, t.tm_hour-8, t.tm_min, t.tm_sec);
}
system("PAUSE");
return 0;
}追问wintc 显示是错的。。。
热心网友 时间:2023-07-11 16:32
在MFC中用timer控件可以实现。
热心网友 时间:2023-07-11 16:32
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
int main()
{
int hour, min, sec;
hour = min = sec = 0;
while(1)
{
Sleep(1000);
system("cls");
sec++;
if ( sec == 60 )
{
min++;
sec = 0;
}
if ( min == 60 )
{
hour = ( hour + 1 ) % 24;
min = 0;
}
printf("%02d:%02d:%02d",hour,min,sec);
}
return 0;
}
热心网友 时间:2023-07-11 16:33
自己想啊,
热心网友 时间:2023-07-11 16:33
这么抽象,谁知道怎么回答啊