描述
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; /* seconds, range 0 to 59 */
int tm_min; /* minutes, range 0 to 59 */
int tm_hour; /* hours, range 0 to 23 */
int tm_mday; /* day of the month, range 1 to 31 */
int tm_mon; /* month, range 0 to 11 */
int tm_year; /* The number of years since 1900 */
int tm_wday; /* day of the week, range 0 to 6 */
int tm_yday; /* day in the year, range 0 to 365 */
int tm_isdst; /* daylight saving time */
};
示例
下麵的例子展示了 gmtime() 函數的用法。
#include <stdio.h>
#include <time.h>
#define BST (+1)
#define CCT (+8)
int main () {
time_t rawtime;
struct tm *info;
time(&rawtime);
/* Get GMT time */
info = gmtime(&rawtime );
printf("Current world clock:\n");
printf("London:%2d:%02d\n", (info->tm_hour+BST)%24, info->tm_min);
printf("China :%2d:%02d\n", (info->tm_hour+CCT)%24, info->tm_min);
return(0);
}
讓我們編譯並運行上麵的程序,將產生以下結果 -
Current world clock: London:14:10 China:21:10
相關用法
- C語言 getarcoords()用法及代碼示例
- C語言 grapherrormsg()用法及代碼示例
- C語言 getchar()用法及代碼示例
- C語言 getc()用法及代碼示例
- C語言 getpixel()用法及代碼示例
- C語言 getx()用法及代碼示例
- C語言 getch()用法及代碼示例
- C語言 getbkcolor()用法及代碼示例
- C語言 gets()用法及代碼示例
- C語言 getdate()、setdate()用法及代碼示例
- C語言 getmaxx()用法及代碼示例
- C語言 gety()用法及代碼示例
- C語言 getenv()用法及代碼示例
- C語言 getmaxy()用法及代碼示例
- C語言 getmaxcolor()用法及代碼示例
- C語言 宏 assert()用法及代碼示例
- C語言 vprintf()用法及代碼示例
- C語言 宏 va_start()用法及代碼示例
- C語言 setlocale()用法及代碼示例
- C語言 fread()用法及代碼示例
注:本文由純淨天空篩選整理自 C library function - gmtime()。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。