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)?
Printable View
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)?
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]
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
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??
Try mktime. You first fill in a tm structure and it converts it to a time_t value.
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]