focus on linux, c/c++, lua

windows时间操作的技巧

// 取得距离到下周X, H点M分剩余的毫秒,用来启动定时器

// 注意传进来的dwTime格式1245(12:45) 305(3:05) 5(00:05) 59(00:59)
DWORD GetNextPeriod(int nDate, DWORD dwTime)
{
time_t now;
time(&now);
tm now_tm = *localtime(&now);
// 精确到分
int nNowMin = now_tm.tm_wday * 24 * 60 + 60 * (now_tm.tm_hour) + now_tm.tm_min;

int nFutureMin = nDate * 24 * 60 + 60 * (dwTime / 100) + (dwTime % 100);

if (nNowMin <= nFutureMin)
{
   return (nFutureMin - nNowMin) * 60 * 1000;
}
return (nFutureMin - nNowMin + 7 * 24 * 60) * 60 * 1000;
}

其他:

time_t now;
time(&now);
tm now_tm = *localtime(&now);

time_t tomorrow = now + (7 - now_tm.tm_wday) * 24 * 3600;
tm tomorrow_tm = *localtime(&tomorrow);
tomorrow_tm.tm_hour = 0;
tomorrow_tm.tm_min = 0;
tomorrow_tm.tm_sec = 0;

time_t OnTimer_t = mktime(&tomorrow_tm);

DWORD dwElapse = (OnTimer_t - now) * 1000;


posted on 2010-10-20 10:10 zuhd 阅读(219) 评论(0)  编辑 收藏 引用 所属分类: c/c++


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理