曲径通幽论坛

标题: gmtime [打印本页]

作者: beyes    时间: 2009-2-20 02:50
标题: gmtime
gmtime() 函数将参数 timep 所指的 time_t 结构中的信息转换成现实世界所使用的时间日期表示方法,然后将结果由结构 struct tm 返回。

#include <time.h>
struct tm *gmtime(const time_t *timeval);

struct tm 结构体内容
int tm_sec               秒,0-61(正常范围为0~59,但允许61秒)
int tm_min               分钟,0-59
int tm_hour              小时,0-23
int tm_mday             一个月中的天数,1-31
int tm_mon              年用的月,0-11(January=0)
int tm_year              自1900年到今的年
int tm_wday              一周中的天,0-6(Sunday=0)
int tm_yday              一年中的天,0-365
int tm_isdst              夏令时标志
  
测试程序
#include <time.h>
#include <stdio.h>
#include <stdlib.h>

int main()
{
         struct tm *tm_ptr;
         time_t the_time;

         (void) time(&the_time);
         tm_ptr = gmtime(&the_time);

         printf("Raw time is %ld\n", the_time);
         printf("gmtime gives:\n");
         printf("date: %02d/%02d/%02d\n",tm_ptr->tm_year,tm_ptr->tm_mon+1,
                                         tm_ptr->tm_mday);
         printf("time: %02d:%02d:%02d\n",tm_ptr->tm_hour,tm_ptr->tm_min,
                                         tm_ptr->tm_sec);
         exit(0);
}

运行及输出
[root@localhost C]# ./gmtime.exe; date
Raw time is 1235099954
gmtime gives:
date: 109/02/20
time: 03:19:14
Fri Feb 20 11:19:14 CST 2009

格林威治时间(GMT, Greenwich Mean Time)
国际协调时(Coordinated Universal Time, UTC)




欢迎光临 曲径通幽论坛 (http://www.groad.net/bbs/) Powered by Discuz! X3.2