首页 > 用户发贴区 > 编程问题提问区 > C语言的时间函数
2008
04-15

#include <stdio.h>
#include <time.h>

void main(){
struct tm *target_time;
time_t rawtime, t;
int year,month,mday,hh,mm,ss;

time ( &rawtime );
target_time = localtime ( &rawtime );

printf(“Please enter year month day hour minute second\n”);
printf(“For example: \n”);
printf(“2008 8 16 9 55 25\n”);
scanf(“%d %d %d %d %d %d”, &year, &month, &mday, &hh,&mm,&ss);
target_time->tm_year = year – 1900;
target_time->tm_mon= month – 1;
target_time->tm_mday = mday ;
target_time->tm_hour = hh ;
target_time->tm_min = mm ;
target_time->tm_sec = ss ;
//
t = mktime (target_time);
// t is ready to use
printf(“%s “,ctime(&t));
}


time ( &rawtime ); //获取当前时间
localtime()//实际上是个转化函数
//把存在rawtime中的时间存成结构体tm..吗??


不是对STRUCT TM的结构体的元素进行输入就可以了吗??那要这两句干什么??


留下一个回复