函数名: ctime
头文件:<time.h>
函数原型: char *ctime(const time_t *time);
功 能: 把日期和时间转换为字符串
参数: 为转换的日期时间
返回值: 返回转换后的字符串指针
补充:
Www Mmm dd hh:mm:ss yyyy
Www 表示星期几
Mmm 是以字母表示的月
dd 表示一月中的第几
hh:mm:ss 表示时
yyyy 表示年份
程序例: 获取系统时间,并转换成字符串,输出结果
#include<stdio.h>#include<time.h>intmain(void){time_tt;//typedeflongtime_t;time(&t);//获取系统时间char*str=ctime(&t);//将时间t转换为字符串printf(Today'sdateandtime:%sn,str);return0;}运行结果:
Today'sdateandtime:TueJun1618:02:262020