time_t t;
struct tm *at;
char now[80];
time(&t);
at = localtime(&t);
strftime(now,sizeof(now),”%Y/%m/%d %H:%M:%S”,at);
每一行都是什么意思啊
struct tm *at;
char now[80];
time(&t);
at = localtime(&t);
strftime(now,sizeof(now),”%Y/%m/%d %H:%M:%S”,at);
每一行都是什么意思啊
解决方案
15
这个问题建议分别查一下每个函数的功能和使用方法;这个几行代码的功能是获取当前时间,然后以一定的格式存放到一个字符数组里;
25
time(&t); //应改为 t=time(NULL);
time_t time(time_t *time)
time_t 类型其实事一个长整型
time()函数:当函数传递参数×time为NULL是,返回一个长整型数值,当传递参数不为NULL时,即代表设定当前时间。
参考函数及数值类型
//参考函数及数值类型:struct tm
struct tm
{
int tm_sec;
int tm_min;
int tm_hour;
int tm_mday;
int tm_mon;
int tm_year;
int tm_wday;
int tm_yday;
int tm_isdst;
size_t strftime( char *str, size_t maxsize, const char *fmt, struct tm *time );
size_t strftime(
char *strDest,
size_t maxsize,
const char *format,
const struct tm *timeptr
);
/×参数列表:函数strftime()的操作有些相似于sprintf():识别以百分号(%)开始的格式命令集合,格式化输出结果放在一个字符串中。格式化命令说明串strDest中各种日期和时间信息的确切表示方法。格式串中的其他字符原样放进串中。格式命令列在下面,它们是区分大小写的。
%a 星期几的简写
%A 星期几的全称
%b 月分的简写
%B 月份的全称
%c 标准的日期的时间串
%C 年份的后两位数字
%d 十进制表示的每月的第几天
%D 月/天/年
%e 在两字符域中,十进制表示的每月的第几天
%F 年-月-日
%g 年份的后两位数字,使用基于周的年
%G 年分,使用基于周的年
%h 简写的月份名×/
}