码迷,mamicode.com
首页 > 其他好文 > 详细

time.h time_t

时间:2014-11-12 07:08:05      阅读:171      评论:0      收藏:0      [点我收藏+]

标签:style   blog   io   color   ar   sp   数据   div   on   

#include <stdio.h>
#include <stddef.h>
#include <time.h>

int main(void)
{
    time_t timer;//time_t就是long int 类型
    struct tm *tblock;
    
//time()获取当前的系统时间,返回的结果是一个time_t类型,其实就是一个大整数,
//其值表示从CUT(Coordinated Universal Time)时间1970年1月1日00:00:00(称为UNIX系统的Epoch时间)到当前时刻的秒数。
    timer = time(NULL);//这一句也可以改成time(&timer);
    printf("The number of seconds since January 1, 1970 is %ld\n",timer);
    
//然后调用localtime将time_t所表示的CUT时间转换为本地时间,并转成struct tm类型,
//该类型的各数据成员分别表示年月日时分秒。
    tblock = localtime(&timer);

//asctime把指向的tm结构体中储存的时间转换为字符串字符串格式
    printf("Local time is: %s\n",asctime(tblock));

    printf("%4d年%02d月%02d日-%02d:%02d:%02d\n",tblock->tm_year+1900,tblock->tm_mon+1,tblock->tm_mday,tblock->tm_hour,tblock->tm_min,tblock->tm_sec);
    
    return 0;
}
//time()结合其他函数(如:localtime、gmtime、asctime、ctime)可以获得当前系统时间或是标准时间。

 

time.h time_t

标签:style   blog   io   color   ar   sp   数据   div   on   

原文地址:http://www.cnblogs.com/x113/p/4091028.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!