VC获取系统时间 请问VC如何获取系统时间,非MFC工程,不支持CString... 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 time();现在用vc的都对c库没概念了嘛?http://msdn.microsoft.com/en-us/library/w4ddyt9h(VS.80).aspx SYSTEMTIME time;GetLocalTime(&time); SYSTEMTIME time;GetLocalTime(&time);通用 SYSTEMTIME time;GetLocalTime(&time); SYSTEMTIME st;GetLocalTime(&st);再把st中的内容转成您想要的格式。 API函数:SYSTEMTIME Time;GetLocalTime(&Time);C/C++:timeb tmb;ftime(&tmb);tm *p_tm = localtime((const time_t *)&tmb.time);char sz_time[1024] ={0}; sprintf(sz_time, "%04d-%02d-%02d %02d:%02d:%02d.%03d", p_tm->tm_year+1900, p_tm->tm_mon+1, p_tm->tm_mday, p_tm->tm_hour, p_tm->tm_min, p_tm->tm_sec, tmb.millitm); 加上头文件#include <sys/timeb.h> 可以用C语言函数time(),也可以用API函数GetLocalTime SYSTEMTIME time;GetLocalTime(&time);这个UP~ 不晓得LZ为什么特别强调不能用CStringvoid GetSystemTime( LPSYSTEMTIME lpSystemTime);void GetLocalTime( LPSYSTEMTIME lpSystemTime); 可能lz建的不是MFC工程,Maybe Win32 Application 接点分. #include <time.h>#include <string>#include <iostream>std::string FormateDateTime(time_t t = time(NULL)){ char szData[256] = {0}; tm* ptm = localtime(&t); sprintf(szData, "%d-%.2d-%.2d %.2d:%.2d:%.2d", ptm->tm_year+1900, ptm->tm_mon+1, ptm->tm_mday, ptm->tm_hour, ptm->tm_min, ptm->tm_sec); return szData;}int main(){ std::string strTime = FormateDateTime(); std::cout << strTime; return 0;} Win32 App不也可以用MFC,哈哈我是没明白CString和时间有啥关系 CString和时间的关系应该就是那个Format吧. static CString strTemp; SYSTEMTIME st; GetLocalTime(&st); // 刷新时间 strTemp.Format("现在时间 %02i:%02i:%02i ",st.wHour,st.wMinute,st.wSecond); GetDlgItem(IDC_CURTIME)->SetWindowText(strTemp); 虽然不是MFC工程,但GetLocalTime()和GetSystemTime()两个函数都可以用呀。我也是这么用的 请教CClientDC和CPaintDC的区别? UNICODE编码下的问题 大家好,问题多多,多多帮忙呀 请问如何通过自定义消息使Edit控件里的内容实现联动? 求救 关于串口和并口的问题 如何能将参与分转化成可用分? 这里我记得以前有啊,为什么现在没有啦?? 调用COM组件的问题 两幅图像之间的连线问题 关于安全删除变量的问题..谢谢了 频繁new 和delete 菜鸟问题 如何得到 Date Time Picker控件的复选框的状态
现在用vc的都对c库没概念了嘛?
http://msdn.microsoft.com/en-us/library/w4ddyt9h(VS.80).aspx
GetLocalTime(&time);
GetLocalTime(&time);
通用
GetLocalTime(&time);
GetLocalTime(&st);再把st中的内容转成您想要的格式。
SYSTEMTIME Time;
GetLocalTime(&Time);
C/C++:
timeb tmb;
ftime(&tmb);
tm *p_tm = localtime((const time_t *)&tmb.time);
char sz_time[1024] ={0};
sprintf(sz_time,
"%04d-%02d-%02d %02d:%02d:%02d.%03d",
p_tm->tm_year+1900,
p_tm->tm_mon+1,
p_tm->tm_mday,
p_tm->tm_hour,
p_tm->tm_min,
p_tm->tm_sec,
tmb.millitm);
#include <sys/timeb.h>
GetLocalTime(&time);这个UP~
void GetSystemTime(
LPSYSTEMTIME lpSystemTime
);
void GetLocalTime(
LPSYSTEMTIME lpSystemTime
);
#include <time.h>
#include <string>
#include <iostream>
std::string FormateDateTime(time_t t = time(NULL))
{
char szData[256] = {0};
tm* ptm = localtime(&t);
sprintf(szData, "%d-%.2d-%.2d %.2d:%.2d:%.2d", ptm->tm_year+1900, ptm->tm_mon+1, ptm->tm_mday, ptm->tm_hour, ptm->tm_min, ptm->tm_sec);
return szData;
}int main()
{
std::string strTime = FormateDateTime(); std::cout << strTime;
return 0;
}
Win32 App不也可以用MFC,哈哈我是没明白CString和时间有啥关系
SYSTEMTIME st;
GetLocalTime(&st);
// 刷新时间
strTemp.Format("现在时间 %02i:%02i:%02i ",st.wHour,st.wMinute,st.wSecond);
GetDlgItem(IDC_CURTIME)->SetWindowText(strTemp);