Timestamp

时间戳的转换,目前知道一种比较笨拙的方法,谁有更好的,恳请赐教:

 1     CTime tm = CTime::GetCurrentTime();
 2     CString str1,str2;
 3     
 4     str2.Format(_T("%d"),tm.GetYear());
 5     str1=str2;
 6     
 7     if(tm.GetMonth()<10)
 8       str2.Format(_T("0%d"),tm.GetMonth());
 9     else
10       str2.Format(_T("%d"),tm.GetMonth());
11     str1+=str2;
12     
13     if(tm.GetDay()<10)
14       str2.Format(_T("0%d"),tm.GetDay());
15     else
16       str2.Format(_T("%d_"),tm.GetDay());
17     str1+=str2;
18     
19     if(tm.GetHour()<10)
20       str2.Format(_T("0%d"),tm.GetHour());
21     else
22       str2.Format(_T("%d"),tm.GetHour());
23     str1+=str2;
24     
25     if(tm.GetMinute()<10)
26       str2.Format(_T("0%d"),tm.GetMinute());
27     else
28       str2.Format(_T("%d"),tm.GetMinute());
29     str1+=str2;
30     if(tm.GetSecond()<10)
31       str2.Format(_T("0%d.txt"),tm.GetSecond());
32     else
33       str2.Format(_T("%d.txt"),tm.GetSecond());
34     str1+=str2;

不足两位的月日时分秒,补零。

这方法实在是太笨拙了,但一时又想不起其他方法,只能凑合着用了。

谢谢。

posted on 2019-08-26 16:47  Milo_lu  阅读(118)  评论(0编辑  收藏  举报

导航