C++ ctime gmtime() Function
Example
Create a tm structure for the current time in the GMT time zone:
time_t now;
struct tm * date;
time(&now);
date = gmtime(&now);
cout << "GMT time: " << asctime(date);
Try it Yourself »
Definition and Usage
The gmtime() function returns a tm structure with date information for a timestamp in the GMT timezone.
The gmtime() function is defined in the <ctime> header file.
The returned tm structure has the following members:
- tm_sec - The seconds within a minute
- tm_min - The minutes within an hour
- tm_hour - The hour within a day (from 0 to 23)
- tm_mday - The day of the month
- tm_mon - The month (from 0 to 11 starting with January)
- tm_year - The number of years since 1900
- tm_wday - The weekday (from 0 to 6 starting with Sunday)
- tm_yday - The day of the year (from 0 to 365 with 0 being January 1)
- tm_isdst - Positive when daylight saving time is in effect, zero when not in effect and negative when unknown
Tip: Use the time() or mktime() functions to create a timestamp.
Syntax
gmtime(time_t * timestamp);
The time_t data type represents a number.
Parameter Values
| Parameter | Description |
|---|---|
| timestamp | Required. A pointer to a timestamp. |
Technical Details
| Returns: | A tm structure representing the date and time of the timestamp in the GMT time zone. |
|---|