Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

C Library Function - gmtime()

C Library Function - gmtime()

C Standard Library - <time.h> C Standard Library -

Description

C Library Function **struct tm gmtime(const time_t timer) Use timer the value to fill in the tm structure, expressed in Coordinated Universal Time (UTC), also known as Greenwich Mean Time (GMT).

Declaration

Below is the declaration of the gmtime() function.



struct tm *gmtime(const time_t *timer)

Parameters

Return Value

This function returns a pointer to a tm structure filled with the time information. The details of the timeptr structure are as follows:

Example

struct

tm

{

int

tm_sec

;

/*

Seconds, ranging from 0 to 59

*/

int

tm_min

;

/*

Minutes, ranging from 0 to 59

*/

int

tm_hour

;

/*

Hours, ranging from 0 to 23

*/

int

tm_mday

;

/*

Day of the month, ranging from 1 to 31

*/

int

tm_mon

;

/*

Month, ranging from 0 to 11

*/

int

tm_year

;

/*

Years since 1900

*/

int

tm_wday

;

/*

Day of the week, ranging from 0 to 6

*/

int

tm_yday

;

/*

Day of the year, ranging from 0 to 365

*/

int

tm_isdst

;

/*

Daylight Saving Time

*/

}

;

Example

The following example demonstrates the use of the gmtime() function.

Example

#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

)

;

}

Let's compile and run the above program, which will produce the following result:



Current world clock:

伦敦:14:10

中国:21:10

C Standard Library - <time.h> C Standard Library -