VOOZH about

URL: https://www.geeksforgeeks.org/c/gmtime-function-in-c-c/

⇱ gmtime() Function in C - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

gmtime() Function in C

Last Updated : 6 Oct, 2023

The gmtime() function in C takes a pointer to type t_time value which represents type in seconds and converts it to struct tm. In this article, we will learn gmtime() Function in the C programming language.

The struct tm type can hold the individual components of time in UTC(Universal Time Coordinated) or GMT time (i.e., the time in the GMT timezone) time zones. The C gmtime() function is defined in <ctime> header file.

Syntax of gmtime()

tm* gmtime ( const time_t* current_time )
  • The hours can be accessed using tm_hour
  • The minutes can be accessed using tm_min
  • The seconds can be accessed using tm_sec

Parameters

  • current_time: It specifies a pointer to a time_t object.

Return Value

  • On Success, returns a pointer to a tm object.
  • Otherwise, the Null pointer is returned.

Examples of gmtime()

Example 1


Output
Current time:
Beijing ( China ):20:00:04
Delhi ( India ): 7:00:04

Example 2


Output
Current time:
Monrovia ( Liberia ) :11:45:36
Buenos Aires ( Argentina ) : 8:45:36
Comment
Article Tags: