C 库函数 - gmtime()

C 语言教程 · 2019-02-24 19:13:55

描述

C 库函数 struct tm *gmtime(const time_t *timer) 使用 timer 的值来填充 tm 结构,并用协调世界时(UTC)也被称为格林尼治标准时间(GMT)表示。

声明

下面是 gmtime() 函数的声明。

struct tm *gmtime(const time_t *timer)

参数

  • timeptr -- 这是指向表示日历时间的 time_t 值的指针。

返回值

该函数返回指向 tm 结构的指针,该结构带有被填充的时间信息。下面是 timeptr 结构的细节:

struct tm {
   int tm_sec;         /* 秒,范围从 0 到 59                */
   int tm_min;         /* 分,范围从 0 到 59                */
   int tm_hour;        /* 小时,范围从 0 到 23                */
   int tm_mday;        /* 一月中的第几天,范围从 1 到 31                    */
   int tm_mon;         /* 月份,范围从 0 到 11                */
   int tm_year;        /* 自 1900 起的年数                */
   int tm_wday;        /* 一周中的第几天,范围从 0 到 6                */
   int tm_yday;        /* 一年中的第几天,范围从 0 到 365                    */
   int tm_isdst;       /* 夏令时                        */    
};

实例

下面的实例演示了 gmtime() 函数的用法。

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

#define BST (+1)
#define CCT (+8)

int main ()
{

   time_t rawtime;
   struct tm *info;

   time(&rawtime);
   /* 获取 GMT 时间 */
   info = gmtime(&rawtime );
   
   printf("当前的世界时钟:\n");
   printf("伦敦:%2d:%02d\n", (info->tm_hour+BST)%24, info->tm_min);
   printf("中国:%2d:%02d\n", (info->tm_hour+CCT)%24, info->tm_min);

   return(0);
}

让我们编译并运行上面的程序,这将产生以下结果:

当前的世界时钟:
伦敦:14:10
中国:21:10

点击查看所有 C 语言教程 文章: https://codercto.com/courses/l/17.html

查看所有标签

Ajax for Web Application Developers

Ajax for Web Application Developers

Kris Hadlock / Sams / 2006-10-30 / GBP 32.99

Book Description Reusable components and patterns for Ajax-driven applications Ajax is one of the latest and greatest ways to improve users’ online experience and create new and innovative web f......一起来看看 《Ajax for Web Application Developers》 这本书的介绍吧!

JS 压缩/解压工具
JS 压缩/解压工具

在线压缩/解压 JS 代码

在线进制转换器
在线进制转换器

各进制数互转换器

Markdown 在线编辑器
Markdown 在线编辑器

Markdown 在线编辑器