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 3341048
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T00:40:41+00:00 2026-05-18T00:40:41+00:00

I am writing a Linux (Ubuntu and Debian Lenny) application in C++. Now I

  • 0

I am writing a Linux (Ubuntu and Debian Lenny) application in C++.

Now I need to know the distance/offset between UTC and the currently set system time at a given day in the past. Since I need to convert recorded data, I the distance need to be calculated with respect to a date in the past (which may have a different DST setting than the current day).

Anyone know how to do this?

Edit: Reading the first answer I think I was misunderstood: I do not want to compare dates/times. I have date/time values which I want to convert from UTC to local time.

  • 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-05-18T00:40:41+00:00Added an answer on May 18, 2026 at 12:40 am

    Prepare the tm structure with date:

    struct tm date;
    memset(&date,0,sizeof(date));
    date.tm_year = year - 1900;
    date.tm_mon = month - 1;
    date.tm_mday = day;
    date.tm_hour = hour;
    date.tm_min = minute;
    date.tm_sec = second;
    date.tm_isdst = -1; // VERY IMPORTANT
    
    mktime(&date); /// fill rest of fields
    

    And then take a look on tm_gmtoff

    printf("%d\n",date.tm_gmtoff);
    

    This is distance from UTC.

    Now this is Linux and BSD specific, it would not work on other stystems, and this works
    with respect to DST.

    Read man mktime for more information. And filling struct tm with correct values

    P.S.: Converting from UTC to Local and back?

    time_t posix_time = timegm(&UTC_Filled_struct_tm); // Linux specific line
    localtime_r(&posix_time,&local_Filled_struct_tm);
    

    Local to UTC

    time_t posix_time = mktime(&local_Filled_struct_tm);
    gmtime_r(&posix_time,&UTC_Filled_struct_tm);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am writing an application in C in GCC (for Linux/Ubuntu) that uses the
I'm writing a few little bash scripts under Ubuntu linux. I want to be
I'm writing a C/C++ application under Linux that reads data from a raw socket
I'm writing a Java application that runs on Linux (using Sun's JDK). It keeps
I'm writing an application that on some stage performs low-level disk operations in Linux
I'm writing a new daemon, which will be hosted on Debian Linux. I've found
I am writing a c++ program on Linux (Ubuntu). I would like to delete
i've been writing some OpenCL code lately on linux (ubuntu 10.4, ati catalyst 10.4
writing a server that runs on linux (Ubuntu) using mono. and a client that
I installed linux (Debian) on an old laptop and have been writing an OpenGL

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.