CTimeSpan时间差
来源:互联网 发布:微信电子相册制作软件 编辑:程序博客网 时间:2024/06/16 22:51
要获取两个时间差,如两个CTime的时间差,可以使用MFC中的CTimeSpan类。
CTime time1 = CTime::GetCurrentTime(); CTime time2 = CTime::GetCurrentTime(); // 两个CTime相减得到CTimeSpan CTimeSpan timeSpan = time2 - time1; // 得到总的秒数 int nTSeconds = timeSpan.GetTotalSeconds();
注意GetTotalSeconds与GetSeconds的区别:GetTotalSeconds返回总的秒数,GetSeconds返回总是小于60,如:如果时间经过了100秒, GetTotalSeconds返回100,而GetSeconds返回40,因为有60秒转为一分钟了,同时使用GetMinutes会返回1,即1分40秒。其它类似函数:
GetDays(); // 返回日数 GetHours(); // 返回小时数(-23至23之间) GetTotalHours(); // 返回总的小时数 GetMinutes(); // 返回分钟数(-59至59之间) GetTotalMinutes(); // 返回总的分钟数 GetSeconds(); // 返回秒数(-59至59之间) GetTotalSeconds(); // 返回总的秒数
例如:
CTimeSpan m_timespan(3,4,5,6); // 3天,4小时,5分,6秒//参数说明
CTime tmToday; //今天的日期 CTime tmPreTwoDay; //前两天的日期 CTimeSpan tmspanTwoDay(2,0,0,0); //两天的时间距离
tmToday=CTime::GetCurrentTime();//获得当前日期 tmPreTwoDay=tmToday-tmspanTwoDay;
// TODO: Add extra validation hereCTime tmToday; //今天的日期 CTime tmPreTwoDay; //前两天的日期 CTimeSpan tmspanTwoDay(1,0,0,0); //两天的时间距离 //CTimeSpan m_timespan(3,4,5,6); // 3天,4小时,5分,6秒CString a;//获取前两天日期for(int i=1;i<3;i++){tmToday=CTime::GetCurrentTime();//获得当前日期 CTimeSpan tmspanTwoDay(i,0,0,0); //两天的时间距离
tmPreTwoDay=tmToday-tmspanTwoDay; a.Format("%02d %02d %02d",tmPreTwoDay.GetYear()%100,tmPreTwoDay.GetMonth(),tmPreTwoDay.GetDay());AfxMessageBox(a);}
0 0
- CTimeSpan时间差
- CTime CTimeSpan 时间差
- CTime以及其它时间差CTimeSpan
- CTime以及其它时间差CTimeSpan
- wtl中使用CTimeSpan计算时间差
- MFC CTIME 对象之间时间差 CTimeSpan
- 时间差
- 时间差
- 时间差
- 时间差
- 时间差
- CTime和CTimeSpan
- CTimeSpan得到日期差
- CTimeSpan得到日期差
- CTime、CTimeSpan、COleDateTime、COleDateTimeSpan
- 【VS开发】CTimeSpan类
- 【VS开发】CTime和CTimeSpan使用
- CTime与CTimeSpanの使い方
- tomcat7中cookie写入中文引发Control character in cookie value or attribute异常
- 硬盘丢失的文件还能恢复吗丨用什么法恢复
- 解决安装MySQL出现Cannot create windows service for mysql.error:0
- 【重大新闻】黑客修改成绩居然是真的
- XML 解析错误:XML 或文本声明不在实体的开头 位置
- CTimeSpan时间差
- makefile的一些有用的东西,自己记录下
- 浅谈partial class的理解
- oddNumFrist
- Spring MVC 集成 Velocity
- iPhone获取键盘高度,通知方式隐藏和显示键盘
- 转载-64位SQL Server 2008的Linked Server连接64位的Oracle--Oracle Provider for OLEDB
- 紫微格局高低
- Xtion Pro使用问题--ROS