Originally Posted by
Salem
mktime - C++ Reference
Fill in a
struct tm for each time, use
mktime() to get a
time_t representation.
Having done that, use
difftime() to work out the difference in seconds.
Thanks for your response however I am still confused about how I would go about getting the input from the user. So far I have...
Code:
public:
void getinfo() //function used to get channel, date and time from the user about a specific device
{
cout<<endl<<endl<<setw(33)<<right<<"Select the channel ==> ";
cin>>channel;
/*The below code prompts the user for a start date/time & a stop date/time*/
cout<<endl<<setw(49)<<right<<"Enter the start date (Day Mon Year) => ";
cin>>start_day>>start_month>>start_year;
cout<<setw(49)<<right<<"Enter the start time (Hour Min Sec) => ";
cin>>start_hour>>start_min>>start_sec;
cout<<endl<<setw(48)<<right<<"Enter the stop date (Day Mon Year) => ";
cin>>stop_day>>stop_month>>stop_year;
cout<<setw(48)<<right<<"Enter the stop time (Hour Min Sec) => ";
cin>>stop_hour>>stop_min>>stop_sec;
/*Test code to process time/date etc from the user!*/
time (&rawtime);
timeinfo = localtime (&rawtime);
timeinfo->tm_year = start_year - 1900;
timeinfo->tm_mon = start_month - 1;
timeinfo->tm_mday = start_day;
}
But I am really unsure if i'm heading in the right direction. I was told by my professor that similar to (where you can use the string data type) there is one for time and date. I still need more clarification on how to go about using mktime and/or any other functions built into the <Ctime> library.
Thanks again!
Edit: I have found the data type for strictly time: http://www.cplusplus.com/reference/clibrary/ctime/time/ but I cannot find anything for date.