CodeGuru Forums -
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic Newsletters VB Forums Developer.com


Newest CodeGuru.com Articles:

  • Deploying Windows Server 2008 with System Center
  • Remote Desktop Protocol Performance Improvements in Windows Server 2008 R2 and Windows 7
  • The Microsoft Dynamics CRM Security Model
  • SQL Server Modeling Services with Microsoft Visual Studio 2010 Beta 2

  • Search CodeGuru:
     



    Go Back   CodeGuru Forums > Visual C++ & C++ Programming > C++ (Non Visual C++ Issues)
    FAQ Members List Calendar Search Today's Posts Mark Forums Read

    C++ (Non Visual C++ Issues) Ask or answer C and C++ questions not related to Visual C++. This includes Console programming, Linux programming, or general ANSI C++.

    Reply
     
    Thread Tools Search this Thread Rate Thread Display Modes
      #1    
    Old November 20th, 2009, 03:00 AM
    rahul.kulshreshtha rahul.kulshreshtha is offline
    Junior Member
     
    Join Date: Nov 2009
    Posts: 18
    rahul.kulshreshtha is an unknown quantity at this point (<10)
    Talking Why My App is crazy with 1 Jan 1970

    Hello I am using the following code to find the seconds passed since 1 Feb 1970
    It is working fine with 1 Feb. If I try to do it for 1 Jan then I get a big 0 in output. Why is it so ?? What to do ?? Currently I am manually adding 2678400 seconds to what I get from 1 Feb.


    #include <time.h>
    #include <ctime>
    #include <iostream>

    using namespace std;

    double dateDifferenceInSeconds(std::time_t date1, std::time_t date2)
    {
    if ( date1 != (std::time_t)(-1) && date2 != (std::time_t)(-1) )
    {
    return std::difftime(date2, date1) ;/// (60 * 60 * 24);
    }
    return NULL;
    }


    int main()
    {
    struct std::tm a = {0,0,0,2,0,70}; /* Feb 1, 1970 */

    time_t currentTime;
    time ( &currentTime );
    time_t x = mktime(&a);


    double timeInSeconds = dateDifferenceInSeconds(x, currentTime);
    printf("\n%.0lf\n",timeInSeconds + 2678400); // Adding seconds of 1 month

    return 0;
    }


    If I use {0,0,0,1,0,70} in place of {0,0,0,2,0,70} for starting it from 1 jan then I get 0 as output
    Reply With Quote
      #2    
    Old November 20th, 2009, 04:05 AM
    srinathduraisamy srinathduraisamy is offline
    Junior Member
     
    Join Date: Jul 2007
    Posts: 12
    srinathduraisamy is an unknown quantity at this point (<10)
    Re: Why My App is crazy with 1 Jan 1970

    What ever time function returns itself is number of seconds elapsed from 1 st jan 1970.
    Why do you want to calculate it separately?
    Reply With Quote
      #3    
    Old November 20th, 2009, 04:10 AM
    rahul.kulshreshtha rahul.kulshreshtha is offline
    Junior Member
     
    Join Date: Nov 2009
    Posts: 18
    rahul.kulshreshtha is an unknown quantity at this point (<10)
    Talking Re: Why My App is crazy with 1 Jan 1970

    Actually I was making a function that will give the difference between two dates/time
    It was working fine with all but when I tested with 1970; it didn't worked.

    Instead of time function you can assume another date in that structure like {0,0,0,1,0,100} for 1 Jan 2000. Forget about time function; tell me for difftime
    Reply With Quote
    Reply

    Bookmarks
    Go Back   CodeGuru Forums > Visual C++ & C++ Programming > C++ (Non Visual C++ Issues)


    Thread Tools Search this Thread
    Search this Thread:

    Advanced Search
    Display Modes Rate This Thread
    Rate This Thread:

    Posting Rules
    You may not post new threads
    You may not post replies
    You may not post attachments
    You may not edit your posts

    BB code is On
    Smilies are On
    [IMG] code is On
    HTML code is Off
    Forum Jump


    All times are GMT -5. The time now is 03:02 PM.



    Acceptable Use Policy


    The Network for Technology Professionals

    Search:

    About Internet.com

    Legal Notices, Licensing, Permissions, Privacy Policy.
    Advertise | Newsletters | E-mail Offers


    Powered by vBulletin® Version 3.7.3
    Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.