MFC 获取两个时间的间隔秒数

我不是稻草人 2010-10-20 04:06:37
我想做一个定时关机的程序。
获取当前时间和一个指定时间的间隔 应该怎么算?
比如我想获取当前时间和每天2:00 的时间间隔秒数

对我来说难点2个。。一个是时间间隔,一个是每天的2:00这个时间怎么获取。。。谢谢大家了。
...全文
625 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
赵4老师 2010-10-20
  • 打赏
  • 举报
回复
COleDateTime
COleDateTimeSpan
shexinwei 2010-10-20
  • 打赏
  • 举报
回复
CTime类中有成员函数可以获取到当前时间:

static CTime WINAPI GetCurrentTime( ) throw( );


以下CTime成员函数可以获取到,日期,秒,分等等:

GetDay
Returns the day represent by the CTime object.

GetDayOfWeek
Returns the day of the week represented by the CTime object.

GetHour
Returns the hour represented by the CTime object.

GetMinute
Returns the minute represented by the CTime object.

GetMonth
Returns the month represented by the CTime object.

GetSecond
Returns the second represented by the CTime object.

GetTime
Returns a __time64_t value for the given CTime object.

GetYear
Returns the year represented by the CTime object.




以下成员函数将一个CTime对象转换为字符串格式:

Format
Converts a CTime object into a formatted string — based on the local time zone.


以下成员函数保证了两个对象可以直接通过- + 操作符:

CTime operator +(
CTimeSpan timeSpan
) const throw( );
CTime operator -(
CTimeSpan timeSpan
) const throw( );
CTimeSpan operator -(
CTime time
) const throw( );
大石头1987 2010-10-20
  • 打赏
  • 举报
回复
用GetTickCount()看有没有这个函数!
chainyu 2010-10-20
  • 打赏
  • 举报
回复
1)APL有获取当前时间的函数 static CTime WINAPI GetCurrentTime() throw();
2)2:00你自己定义一个数据
龙哥依旧 2010-10-20
  • 打赏
  • 举报
回复
看看CTime和CTimeSpan类就可以解决了
拉卡尼休 2010-10-20
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 lightboat09 的回复:]
每30秒判断一下是否到点了
[/Quote]

那不累死啊,哪有这么干的。

你只要算出来到下一个2:00时间间隔是多少,然后关机就行了,关机后重启再打开程序还是一样的逻辑。

具体函数Google一下吧,不提供了。
小楫轻舟 2010-10-20
  • 打赏
  • 举报
回复
每30秒判断一下是否到点了

64,645

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧