CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Apr 1999
    Posts
    13

    C Program to display time left til Year 2000

    Does anybody have a C program that prompts the user for a date and returns the time left to the year 2000 (from the date the user entered)?




  2. #2
    Guest

    Re: C Program to display time left til Year 2000

    The time command gives the number of seconds that have passed
    since midnight, Greenwich time, Jan 1 1970. Figure out how many
    seconds from then to Y2K and subtract (time), and you've got it.

    Cheers,
    Jason F.
    [email protected]


  3. #3
    Join Date
    Apr 1999
    Posts
    13

    Re: C Program to display time left til Year 2000

    I hate to sound like an idiot, although when it comes to programming I must admit I am. Anyway, do you have any examples using this command. I've tried doing some things, but am not having much success.
    Jody


  4. #4
    Join Date
    Apr 1999
    Posts
    13

    Re: C Program to display time left til Year 2000

    Ok, I king of figured out the time command.

    How do I use the time command with a date and time entered from the keyboard, instead of it using the current system date/time??


  5. #5
    Join Date
    May 1999
    Location
    Oregon, USA
    Posts
    302

    Re: C Program to display time left til Year 2000

    Try mktime. You first fill in a tm structure and it converts it to a time_t value.



  6. #6
    Guest

    Re: C Program to display time left til Year 2000

    It's easy with MFC. Start a new project in VC 6. Select "Console app with MFC support." Enter this in the "to do" section:

    CTime curtime(CTime::GetCurrentTime());
    CTime time2000(2000,1,1,0,0,0);
    CTimeSpan remaining = time2000 - curtime;
    CString outpt;
    outpt.Format("Time left until armageddon: %d days, %d hours, %d minutes, %d seconds", remaining.GetDays(), remaining.GetHours(), remaining.GetMinutes(), remaining.GetSeconds());
    cout << (LPCTSTR)outpt << endl;



    mailto:[email protected]




Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured