获取当前系统时间的方法一:
CTime time = CTime::GetCurrentTime(); |
| //构造CTime对象 |
int m_nYear = time.GetYear(); |
| //年 |
int m_nMonth = time.GetMonth(); |
| //月 |
int m_nDay = time.GetDay(); |
| //日 |
int m_nHour = time.GetHour(); |
| //小时 |
int m_nMinute = time.GetMinute(); |
| //分钟 |
int m_nSecond = time.GetSecond(); |
| //秒 |
还可以用CTime::Format函数将CTime对象转换为字符串对象
CTime t = CTime::GetCurrentTime();
Cstring date =t.Format("%Y年%m月%d日");
Cstring week =t.Format("%a");
Cstring time =t.Format("%H:%M");
方法二:
CStringstr;
time_t t;
struct tmtmtime;
time(&t);
localtime_s(&tmtime,&t);
str1.Format("%02u:%02u:%02u",tmtime.tm_hour, tmtime.tm_min, tmtime.tm_sec);