/*设置系统日期 <time.h>头文件*/
struct tm *tm_ptr;
time_t the_time;
time(&the_time);
tm_ptr=localtime(&the_time);
sprintf(buf2,"%d-%d-%d",tm_ptr->tm_year+1900,tm_ptr->tm_mon+1,tm_ptr->tm_mday); //获取系统日期
本文介绍了一种使用C语言获取当前系统日期的方法。通过调用<time.h>库中的time()函数来获取时间戳,并利用localtime()将时间戳转换为本地时间结构,最后通过sprintf()函数格式化输出日期。
/*设置系统日期 <time.h>头文件*/
struct tm *tm_ptr;
time_t the_time;
time(&the_time);
tm_ptr=localtime(&the_time);
sprintf(buf2,"%d-%d-%d",tm_ptr->tm_year+1900,tm_ptr->tm_mon+1,tm_ptr->tm_mday); //获取系统日期
3212
1万+
1421

被折叠的 条评论
为什么被折叠?