MFC 获取系统时间及比较

1、MFC 获取当前系统时间
CTime time = CTime::GetCurrentTime(); //获取系统日期
CString strDate = time.Format(_T("%x"));          //格式化日期  
CString strTime = time.Format(_T("%X"));          //格式化时间  
CString date = time.Format(_T("%Y-%m-%d %H:%M:%S %W-%A"));//2006-10-13 17:23:47 41-Friday

Format函数的格式符号及其意义:

  • %a: 简写的星期名,例如Sat代表Saturday
  • %A: 全写星期(英文),如Friday
  • %b: 简写的月名,例如Mar代表March
  • %B: 月份(全写英文),如October
  • %c: 月/日/年 时:分:秒,如1/3/2012 21:19:11
  • %d: 月中的天数,值为01~31
  • %H: 24小时格式的小时数,值为00~23
  • %I: 通常的12小时格式的小时数,值为01~12
  • %j: 一年当中的第几天,值为001~336
  • %m: 月数,值为01~12
  • %M: 分钟数,值为00~59
  • %p: 由12小时格式的时钟指示的am/pm(上午/下午)
  • %S: 秒数,值为00~59
  • %U: 年中的周数,值为00~53,以周日为一周的第一天
  • %w: 周中的日期数,值为0~6,其中0为周日
  • %W: 年中的周数,值为00~53,以周一为一周的第一天
  • %x: 月/日/年,%c的前半段
  • %X: 时/分/秒,%c的后半段
  • %y: 不带年代前缀的年数,值为00~99
  • %Y: 年份(带世纪,如2006)
  • %z: 简写的时区名称
  • %Z: 时区名称的全称,如果时区未知,此字符为空,如“中国标准时间”
2、MFC 时间比较

如果当前时间大于指定的时间,函数返回false

bool PubFunc::CompareTime(int nYear, int nMonth, int nDay)
{
	CTime t(nYear, nMonth, nDay, 0, 0, 0);
	if (CTime::GetCurrentTime() > t)
		return FALSE;
	return true;
}
3、Win32 获取当前系统时间
char* pBuf = new char[256];
memset(pBuf, 0, 256);
SYSTEMTIME time;
GetLocalTime(&time);
sprintf(pBuf, "%02d.%02d %02d:%02d:%02d.%03d",
	time.wMonth, time.wDay, time.wHour, time.wMinute, time.wSecond, time.wMilliseconds);
  • 3
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值