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> CTime nowtime = CTime::GetCurrentTime();<BR> m_sNowTime = nowtime.Format(_T("%Y-%m-%d %H:%M:%S"));<BR><BR> 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> ASSERT(pCtrl != NULL);<BR><BR> // get as a CTime<BR> CTime timeTime;<BR> DWORD dwResult = pCtrl->GetTime(timeTime);<BR> if (dwResult == GDT_VALID)<BR> {<BR> // the user checked the box and specified data<BR> CString str;<BR><BR> // is it a time-only control, or a date-only control?<BR> if ((pCtrl->GetStyle() & DTS_TIMEFORMAT) == DTS_TIMEFORMAT)<BR> str = timeTime.Format(_T("%X"));<BR> else<BR> str = timeTime.Format(_T("%x"));<BR> AfxMessageBox(str);<BR> }<BR> else<BR> {<BR> // the user unmarked the "none" box<BR> AfxMessageBox(_T("Time not set!"));<BR> }<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 + -
显示快捷键?