发布网友 发布时间:2023-10-25 11:54
共3个回答
热心网友 时间:2024-11-15 18:22
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
void main ()
{
time_t rawtime;
struct tm * timeinfo;
time ( &rawtime );
timeinfo = localtime ( &rawtime );
printf ( "\007The current date/time is: %s", asctime (timeinfo) );
//exit(0);
int year,month,day,hour,minute,second;
year = 1900+timeinfo->tm_year; //年
month = 1+timeinfo->tm_mon;//月
day = timeinfo->tm_mday; //日
hour = timeinfo->tm_hour; //时
minute = timeinfo->tm_min; //分
second = timeinfo->tm_sec; //秒
printf("%d-%d-%d %d:%d:%d\n",year,month,day,hour,minute,second);
}
追答
给个好评吧,程序和截图如下:
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
void main ()
{
time_t now_time=time(0); //这是你要这样写的,其实差不多
struct tm * timeinfo;
timeinfo = localtime ( &now_time );
printf("%s\n",asctime (timeinfo));
int year,month,day,hour,minute,second;
year = 1900+timeinfo->tm_year; //年
month = 1+timeinfo->tm_mon;//月
day = timeinfo->tm_mday; //日
hour = timeinfo->tm_hour; //时
minute = timeinfo->tm_min; //分
second = timeinfo->tm_sec; //秒
printf("%d-%02d-%d %d:%d:%d\n",year,month,day,hour,minute,second);
}
热心网友 时间:2024-11-15 18:23
char tmp[30];//日期时间信息存储位置热心网友 时间:2024-11-15 18:23
GetLocalTime