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

  • Home
  • SEARCH
  • 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 8436843
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T07:17:33+00:00 2026-06-10T07:17:33+00:00

I am executing below code. int main() { struct tm storage={0,0,0,0,0,0,0,0,0}; char *p =

  • 0

I am executing below code.

int main()
{
struct tm storage={0,0,0,0,0,0,0,0,0};
char *p = NULL; 
p = (char *)strptime("2012-08-25 12:23:12","%Y-%m-%d %H:%M:%S",&storage);
char buff[1024]={0};
strftime(buff,1024,"%Y-%m-%d %H:%M:%S",&storage);
cout << buff << endl;
storage.tm_sec += 20;
strftime(buff,1024,"%Y-%m-%d %H:%M:%S",&storage);
cout << buff << endl;
mktime(&storage);
strftime(buff,1024,"%Y-%m-%d %H:%M:%S",&storage);
cout << buff << endl;
return 0;
}

If above Program executed, It prints ‘ 2012-08-25 13:23:32’ instead of ‘2012-08-25 12:23:32’. Please Help, why it is increasing tm_hour value.
This works correctly if I put input date as ‘2012-02-25 12:23:32’ in program, which is confusing.

OUtput ->

[user@rtpkvm55-vm2 root]$ ./a.out
2012-08-25 12:23:12
2012-08-25 12:23:32
2012-08-25 13:23:32
[user@rtpkvm55-vm2 root]$

Date Info on my system, –>

[user@rtpkvm55-vm2 root]$ date
Sat Aug 25 08:28:26 EDT 2012
  • 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-10T07:17:34+00:00Added an answer on June 10, 2026 at 7:17 am

    What happens

    The date you specified has daylight savings in effect but when calling mktime, storage.tm_isdst is zero. mktime sees this and thinks “hey, they gave me a date with an incorrect daylight savings flag, lets fix it”. Then it sets tm_isdst to 1 and changes tm_hour.

    See also this answer.

    To fix it

    • use timegm instead of mktime
    • set the timezone to UTC before calling mktime (see also example from timegm) :
      setenv("TZ", "", 1);
      tzset();
      mktime();
    • use a good date-time library (like boost::locale::date_time/boost::date_time, but read the Q&A section on the boost::locale::date_time page before picking one)
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code below #include <stdio.h> int main(){ int i=0; for(i=0; i<1000; i++)
The code below is not executing. I'm calling it as NameManager.main(fsitem); from my main
I am executing below code successfully without any errors but when I am executing
Executing the below code gives me the following exception on the last line: InvalidOperationException:
A user is getting an error on their phone when executing the code below,
This code below is for executing ls -l | wc -l. In the code,
I am getting some Stack Over Flow Exception while I am executing below code.
While executing the code below I am getting HTTP 500 Internal Server Error. public
see i have one code like this int main () { uint32_t i ;
I have to perform async execution, and i have wrote the below code var

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.