如何通过time.h ...输入将来的时间,以及如何找到"check in"之间的时间差.和“结帐时间"? [英] how to input a time which is in the future through time.h .....and how to find time difference between the "check in" and "check out time"?
本文介绍了如何通过time.h ...输入将来的时间,以及如何找到"check in"之间的时间差.和“结帐时间"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
struct tm * timeinfo;
time ( &rawtime );
timeinfo = localtime ( &rawtime );
cout<<"The Check in time is : " <<asctime (timeinfo);
ofstream customerfile ("customers.txt", ios::out | ios::app );
string day;
string month;
string date;
cout<<"Please fill the check out time data :"<<endl;
cout<<"The Day of check out : \n";
cin>>day;
cout<<"The Month of check out : \n";
cin>>month;
cout<<"The Date of check out : \n";
cin>>date;
string chkout = day + month + date + (asctime (timeinfo)+10);
if (customerfile.is_open())
{
customerfile<< asctime (timeinfo)<<","<< chkout<<"\n";}
customerfile.close();
system ("pause");
goto Main_Menu;
break;
}
推荐答案
使用mktime
函数创建将来的时间.
将值填写在tm
结构中,并将其传递给mktime
函数.
要获取两个时间值之间的差,请使用difftime
函数.
Use themktime
function to create a future time.
Fill in the values in atm
structure and pass this to themktime
function.
To get the difference between 2 time values, use thedifftime
function.
在使用C ++时,请不要运行到 ^ ]并获取其库的最新版本.日期/时间库非常干净且实用,但是会在编译时浪费时间(每个源文件几秒钟).
As you''re using C++ I''d run, not walk over to Boost[^] and grab the latest version of their library. The date/time library is pretty clean and functional but it''ll clonk some time on your compilation (a couple of seconds per source file).
这篇关于如何通过time.h ...输入将来的时间,以及如何找到"check in"之间的时间差.和“结帐时间"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文