Click to See Complete Forum and Search --> : C Program to display time left til Year 2000


Jody
April 24th, 1999, 01:20 PM
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)?

April 25th, 1999, 02:15 AM
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.
jfahy@sprint.ca

Jody
April 25th, 1999, 09:20 PM
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

Jody
April 26th, 1999, 08:37 AM
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??

Gomez Addams
April 26th, 1999, 12:40 PM
Try mktime. You first fill in a tm structure and it converts it to a time_t value.

April 27th, 1999, 11:16 AM
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:crandall@msen.com