首页 > 代码库 > 时间函数
时间函数
#include<time.h>//系统当前日历的时间time_t time(time_t *time);//返回以tm结构存储的一个时间struct tm *localtime(const time_t *time);//返回字符串形式的时间表示char *asctime(const struct tm *ptr);//返回以tm结构存储的一个UTC时间,就是格林尼治时间struct tm *gmtime(const time_t *time);
以上是时间函数,具体使用如下:
1 #include<stdio.h> 2 #include<time.h> 3 4 int main(void) 5 { 6 struct tm *local; 7 time_t tm; 8 9 tm=time(NULL);10 11 local=localtime(&tm);12 13 printf("Local time and date is: %s\n",asctime(local));14 15 local=gmtime(&tm);16 printf("TUC time an date id : %s\n",asctime(local));17 18 return 0;19 }
结果是
Local time and date is: Sun Sep 7 15:01:54 2014
TUC time an date id : Sun Sep 7 07:01:54 2014
可以看出二者形式类似,通过asc转换出来的字符串形式。
gm和local都是接受time返回的time,将其转换为标准时间存储到结构tm中,并通过asc进行字符串转换并显示。
时间函数
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。