请问在 VC 中如何获得系统时间,并转化成字符串格式。

urchinman 2003-01-15 09:38:21
请问在 VC 中如何获得系统时间,并转化成字符串格式。
...全文
305 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
HowUCan 2003-01-15
  • 打赏
  • 举报
回复
Windows和Unix都能用:

time_t timeNow;
struct tm *ptmNow;
char szTime[30];
timeNow = time(NULL);
ptmNow = localtime(&timeNow);

sprintf(szTime, "%d.%d.%d %d:%d:%d", ptmNow->tm_year+1900, ptmNow->tm_mon, ..., ptmNow->tm_sec);
yndfcd 2003-01-15
  • 打赏
  • 举报
回复
GetTimeFormat(LOCALE_SYSTEM_DEFAULT, 0, NULL,NULL, pszTimeStr, nLength);
一个函数就搞定。
ljl2002cn 2003-01-15
  • 打赏
  • 举报
回复
char szTime[20];
SYSTEMTIME SysTime;

memset(szTime,0,20);
GetSystemTime(&SysTime);

sprintf(szTime,"%d年%d月%d 日",SysTime.wYear,SysTime.wMonth,SysTime.wDay);
LinHanLao 2003-01-15
  • 打赏
  • 举报
回复
SYSTEMTIME systime;
::GetSystemTime(&systime);
CTime t(systime, -1);
CString kk = t.Format("%Y:%m:%d:%H:%M:%S");

绝对可用,年月日时分秒
LinHanLao 2003-01-15
  • 打赏
  • 举报
回复
不好意思,搞错了

先用 ::GetSystemTime()
然后用 CString::Format()
librastar2001 2003-01-15
  • 打赏
  • 举报
回复
CTime CurrentTime=CTime::GetCurrentTime();
CString CurrentTimeString=CurrentTime.Format();
Jazzlover 2003-01-15
  • 打赏
  • 举报
回复
CTime time = CTime::GetCurrentTime();
CString strTime ;
strTime.Format(
"%d-%d-%d-%d-%d-%D",time.GetYear(),time.GetMonth(),time.GetDay(),time.GetHour(),time.GetMinute(),time.GetSecond());
LinHanLao 2003-01-15
  • 打赏
  • 举报
回复
CTime t = CTime::GetCurrentTime();
CString CTime::Format( LPCTSTR pFormat ) const

LinHanLao 2003-01-15
  • 打赏
  • 举报
回复
CTime t = CTime::GetCurrentTime();
CString Format( LPCTSTR pFormat ) const
mengxihe 2003-01-15
  • 打赏
  • 举报
回复
CString s;
COleDateTime col = COleDateTime::GetCurrentTime();
s = col.Format("%Y-%m-%d %H-%M-%S");
vc8 2003-01-15
  • 打赏
  • 举报
回复
同意 HowUCan(上下班别忘刷卡)
galedellgps 2003-01-15
  • 打赏
  • 举报
回复
如果是支持MFC的话,librastar2001(librastar)的方法最简单。

15,979

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 界面
社区管理员
  • 界面
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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