Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8408639
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T23:41:19+00:00 2026-06-09T23:41:19+00:00

I wanted to calculate the time difference for a GMT time and current time.

  • 0

I wanted to calculate the time difference for a GMT time and current time. For this I am converting tm time (which is in GMT) to time_t format using mktime. and current time using time() api.

struct tm = x;  time_t t1, t2; 
time(&t1);
/* here x  will get in GMT format */
t2 = mktime(&x);
sec = difftime(t2 , t1);

In this for making the same time zone, is mktime() will take care of converting to local time ? or shall I need to explicitly add sec = difftime(t2 , gmtime(&t1);
Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T23:41:21+00:00Added an answer on June 9, 2026 at 11:41 pm

    Yes mktime convert to local time, please read the man:

    http://www.mkssoftware.com/docs/man3/mktime.3.asp

    mktime() : convert local time to seconds since the Epoch
    

    EDIT : To calculate the difference time between two dates, you can use this

        time_t t1, t2;
        struct tm my_target_date;
    
        /* Construct your date */
        my_target_date.tm_sec = 0;
        my_target_date.tm_min = 0;
        my_target_date.tm_hour = 0;
        my_target_date.tm_mday = 20;
        my_target_date.tm_mon = 7;
        my_target_date.tm_year = 112; /* Date today */
        t1 = mktime (&my_target_date);
        t2 = time (NULL);
        printf ("Number of days since target date : %ld\n", (t2 - t1) / 86400); /* 1 day = 86400 sec, use 3600 if you want hours */
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Rather than using WMI to obtain the last boot time, I wanted to calculate
Recently I was trying to determine the time needed to calculate a waveform using
I wanted to calculate sin inverse ..so i did this: float radians = asinf(1.1205);
What I wanted to achieve is being able to calculate the height and width
Wanted to understand the difference between undef and define a macro as 0. Thanks.
I wanted to calculate the angle between two vectors but I have seen these
Just wanted to know if this function's results will always hold? private int calcHourDiff(int
I wanted to calculate the median I don't know what is wrong here UPDATE:
I have a loop in which I calculate a value and add it it
I am using Python to read in data in a user-unfriendly format and transform

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.