VOOZH about

URL: https://www.geeksforgeeks.org/c/convert-the-local-time-to-gmt-in-c/

⇱ Convert the Local Time to GMT in C - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Convert the Local Time to GMT in C

Last Updated : 15 Jun, 2025

Time zone handling is a mandatory feature for applications that work across multiple geographical regions. This includes the conversion of time from one time zone to another.
There are only two natively supported time types in the standard C library via <time.h>, which are the local time and Greenwich Mean Time (GMT), also known as Coordinated Universal Time (UTC).

In this practice Problem, we will learn a complete implementation for converting local time to Greenwich Mean Time (GMT) in C language.

Prerequisite: C Basics, Time Library in C.

Implementation

Step 1: Initial setup

The initial setup includes importing the header files, creating a structure ( tm) to hold the values ,and creating other variables like raw_time( to store raw time) , is_ds,t etc.

Step 2: Taking Local Time from User

In this step the the program asks for user inputs which refers to the local time and the values in the structure tm is updated according to the local time given by the user.

Step 3: Getting raw time from local time

In this step we will use the mktime() function infected from the time.h header which converts the local time into raw time and store the detail result into raw_time variable.

This step also check for invalid time input.

Step 4: Converting the raw time to GMT and printing the results.

For this step we will use the `gmtime()` function to convert the raw time to GMT; again, we will use `asctime()` to convert the time to a string and print the result.

Final Execution

Now we combine all of the above steps to get the executable source code for the program:

For the following input values:

13 06 2025
08 48 25

Output

Local Time: Fri Jun 13 08:48:25 2025
GMT Time: Fri Jun 13 03:18:25 2025
Comment
Article Tags: