gmtime ()- 转换时间
格式
#include <time.h>
struct tm *gmtime(const time_t *time);语言级别
ANSI
线程安全
False
请改为使用 gmtime_r() 。
描述
The gmtime() function breaks down the 时间 value, in seconds, and stores it in a 特姆 structure, defined in <time.h>. The value 时间 is usually obtained by a call to the time() function.
tm 结构的字段包括:
- 秒
- 秒 (0-61)
- tm_min
- 分钟 (0-59)
- 小时
- 小时数 (0-23)
- 星期
- 月内日期 (1-31)
- tm_mon
- 月 (0-11; 一月 = 0)
- 年份
- 年份 (本年度减去 1900 年)
- 星期几
- 星期几 (0-6; 星期日 = 0)
- tm_yday
- 一年中的第几天 (0-365; 一月 1 = 0)
- tm_isdst
- 如果夏令时未生效,那么为零; 如果夏令时生效,那么为正; 如果信息不可用,那么为负。
返回值
gmtime() 函数返回指向生成的 tm 结构的指针。注:
- tm_sec 的范围 (0-61) 允许多达 2 个闰秒。
gmtime()和localtime()函数可以使用公共的静态分配缓冲区进行转换。 对其中一个函数的每个调用都可能更改先前调用的结果。- 日历时间是自 EPOCH 以来经过的秒数,即 00:00:00 , 1970 年 1 月 1 全球标准时间 (UTC)。
示例
此示例使用
gmtime() 函数将 time_t 表示调整为全球标准时间字符串,然后使用 asctime() 函数将其转换为可打印字符串。#include <stdio.h>
#include <time.h>
int main(void)
{
time_t ltime;
time(<ime);
printf ("Coordinated Universal Time is %s\n",
asctime(gmtime(<ime)));
}
/************************ Output should be similar to: **********
Coordinated Universal Time is Wed Aug 18 21:01:44 1993
*/
相关信息
- asctime ()-将时间转换为字符串
- asctime_r ()-将时间转换为字符串 (可重新启动)
- ctime ()-将时间转换为字符串
- ctime64()-将时间转换为字符串
- ctime64_r()-将时间转换为字符串 (可重新启动)
- ctime_r ()-将时间转换为字符串 (可重新启动)
- gmtime64()-转换时间
- gmtime64_r()-转换时间 (可重新启动)
- gmtime_r ()-转换时间 (可重新启动)
- localtime ()-转换时间
- localtime64()-转换时间
- localtime64_r()-转换时间 (可重新启动)
- localtime_r ()-转换时间 (可重新启动)
- mktime ()-转换本地时间
- mktime64()-转换本地时间
- setlocale ()-设置语言环境
- time ()-确定当前时间
- time64()-确定当前时间
- <time.h>