曲径通幽论坛

 找回密码
 立即注册
搜索
查看: 4353|回复: 0
打印 上一主题 下一主题

gmtime

[复制链接]

4918

主题

5880

帖子

3万

积分

GROAD

曲径通幽,安觅芳踪。

Rank: 6Rank: 6

积分
34395
跳转到指定楼层
楼主
发表于 2009-2-20 02:50:05 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
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)
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|曲径通幽 ( 琼ICP备11001422号-1|公安备案:46900502000207 )

GMT+8, 2025-5-9 04:35 , Processed in 0.083327 second(s), 23 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表