C语言ctime函数

来源:互联网 发布:诺里尔斯克 知乎 编辑:程序博客网 时间:2024/05/22 12:30

ctime函数原型:

#include <time.h>

char *ctime(const time_t *timeval);

ctime以原始时间值为参数,并将其转换为一个更易读的本地时间。原始时间是指以格林尼治时间(GMT)1970年1月1日午夜(0点)为纪元,到现在为止的秒数。函数time()可以得到该原始时间。

time函数原型:

#include <time.h>

time_t time(time_t *tloc);

功能是返回从纪元(格林尼治时间(GMT)1970年1月1日午夜(0点))开始至今的秒数。如果tloc不是一个空指针,time函数还会将返回值写入tloc所指向的位置。

例:

#include <time.h>#include <stdio.h>#include <stdlib.h>int main(){time_t the_time;(void*)time(&the_time);printf("the time: %s\n",ctime(&the_time));exit(0);}


原创粉丝点击