C語言time頭文件(time.h)中gmtime函數的用法及代碼示例。
用法:
struct tm * gmtime (const time_t * timer);
將time_t轉換為tm作為UTC時間
有關本地時間的替代方法,請參見localtime。
參數
返回值
指向一個的指針tm其成員填充有與UTC時間表示相對應的值的結構timer。返回的值指向一個內部對象,該對象的有效性或值可以通過隨後的任何調用來更改gmtime或者localtime。
示例
/* gmtime example */
#include <stdio.h> /* puts, printf */
#include <time.h> /* time_t, struct tm, time, gmtime */
#define MST (-7)
#define UTC (0)
#define CCT (+8)
int main ()
{
time_t rawtime;
struct tm * ptm;
time ( &rawtime );
ptm = gmtime ( &rawtime );
puts ("Current time around the World:");
printf ("Phoenix, AZ (U.S.) : %2d:%02d\n", (ptm->tm_hour+MST)%24, ptm->tm_min);
printf ("Reykjavik (Iceland) : %2d:%02d\n", (ptm->tm_hour+UTC)%24, ptm->tm_min);
printf ("Beijing (China) : %2d:%02d\n", (ptm->tm_hour+CCT)%24, ptm->tm_min);
return 0;
}
輸出:
Current time around the World: Phoenix, AZ (U.S.) : 8:22 Reykjavik (Iceland) : 15:22 Beijing (China) : 23:22 |
相關用法
- C語言 clock用法及代碼示例
- C語言 difftime用法及代碼示例
- C語言 mktime用法及代碼示例
- C語言 time用法及代碼示例
- C語言 asctime用法及代碼示例
- C語言 ctime用法及代碼示例
- C語言 localtime用法及代碼示例
- C語言 strftime用法及代碼示例
注:本文由純淨天空篩選整理自C標準庫大神的英文原創作品 C gmtime function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。