subject_15895.htm

来自「一些关于vc的问答」· HTM 代码 · 共 12 行

HTM
12
字号
<p>
序号:15895 发表者:ahyu 发表日期:2002-09-23 16:11:55
<br>主题:想要得到日期时间,用CDateTimeCtrl怎么得到??
<br>内容:麻烦高手们给个简单例子!
<br><a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p>
<hr size=1>
<blockquote><p>
<font color=red>答案被接受</font><br>回复者:徐景周 回复日期:2002-09-23 16:28:00
<br>内容:<BR>可试试下面方法:<BR>//初始更新闹钟显示<BR>&nbsp;&nbsp;&nbsp;&nbsp;CTime nowtime = CTime::GetCurrentTime();<BR>&nbsp;&nbsp;&nbsp;&nbsp;m_sNowTime = nowtime.Format(_T("%Y-%m-%d %H:%M:%S"));<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;m_Time = CTime(nowtime.GetYear(),nowtime.GetMonth(),nowtime.GetDay(),nowtime.GetHour(),nowtime.GetMinute(),nowtime.GetSecond());<BR><BR>CDateTimeCtrl可用GetTime获取一个CTime时间类型,如下:<BR>CDateTimeCtrl* pCtrl = (CDateTimeCtrl*) GetDlgItem(IDC_DATETIMEPICKER1);<BR>&nbsp;&nbsp; ASSERT(pCtrl != NULL);<BR><BR>&nbsp;&nbsp; // get as a CTime<BR>&nbsp;&nbsp; CTime timeTime;<BR>&nbsp;&nbsp; DWORD dwResult = pCtrl-&gt;GetTime(timeTime);<BR>&nbsp;&nbsp; if (dwResult == GDT_VALID)<BR>&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// the user checked the box and specified data<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;CString str;<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// is it a time-only control, or a date-only control?<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if ((pCtrl-&gt;GetStyle() & DTS_TIMEFORMAT) == DTS_TIMEFORMAT)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; str = timeTime.Format(_T("%X"));<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; str = timeTime.Format(_T("%x"));<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;AfxMessageBox(str);<BR>&nbsp;&nbsp; }<BR>&nbsp;&nbsp; else<BR>&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// the user unmarked the "none" box<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;AfxMessageBox(_T("Time not set!"));<BR>&nbsp;&nbsp; }<BR><BR>
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?