gmtime_r ()- 转换时间 (可重新启动)
格式
#include <time.h>
struct tm *gmtime_r(const time_t *time, struct tm *result);语言级别
XPG4
线程安全
是
描述
此函数是 gmtime()的可重新启动版本。
gmtime_r() 函数分解 time 值 (以秒为单位) ,并将其存储在 result中。 结果 is a pointer to the 特姆 structure, defined in <time.h>. The value time 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_r() 函数返回指向生成的 tm 结构的指针。注:
- tm_sec 的范围 (0-61) 允许多达 2 个闰秒。
gmtime()和localtime()函数可以使用公共的静态分配缓冲区进行转换。 对其中一个函数的每个调用都可能更改先前调用的结果。asctime_r(),ctime_r(),gmtime_r()和localtime_r()函数不使用公共的静态分配缓冲区来保存返回字符串。 如果需要重新环境,那么可以使用这些函数来代替asctime(),ctime(),gmtime()和localtime()函数。- 日历时间是自 EPOCH 以来经过的秒数,即 00:00:00 , 1970 年 1 月 1 全球标准时间 (UTC)。
示例
此示例使用
gmtime_r() 函数将 time_t 表示调整为全球标准时间字符串,然后使用 asctime_r() 函数将其转换为可打印字符串。#include <stdio.h>
#include <time.h>
int main(void)
{
time_t ltime;
struct tm mytime;
char buf[50];
time(<ime)
printf ("Coordinated Universal Time is %s\n",
asctime_r(gmtime_r(<ime, &mytime), buf));
}
/************************ 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 ()-将时间转换为字符串 (可重新启动)
- gmtime ()-转换时间
- gmtime64()-转换时间
- gmtime64_r()-转换时间 (可重新启动)
- localtime ()-转换时间
- localtime64()-转换时间
- localtime64_r()-转换时间 (可重新启动)
- localtime_r ()-转换时间 (可重新启动)
- mktime ()-转换本地时间
- mktime64()-转换本地时间
- time ()-确定当前时间
- time64()-确定当前时间
- <time.h>