CDateTimeCtrl::GetTime

从日期和时间选择器控件在指定的 SYSTEMTIME 结构检索当前所选时间并将其放在

BOOL GetTime(
   COleDateTime& timeDest 
) const;
DWORD GetTime(
   CTime& timeDest 
) const;
DWORD GetTime(
   LPSYSTEMTIME pTimeDest 
) const;

参数

  • timeDest
    在第一个版本,要获取系统时间信息的 COleDateTime 对象的引用。 在第二个版本,要获取系统时间信息的 CTime 对象的引用。

  • pTimeDest
    为获取系统时间信息的 SYSTEMTIME 结构的指针。 不能 NULL

返回值

在第一个版本,非零,如果时间。COleDateTime 对象已成功编写;否则为0。 在第二个和第三个版本,DWORD 值等于在 NMDATETIMECHANGE framework安装的 dwFlag 成员。 请参见下面 Remarks 部分有关更多信息。

备注

此成员函数实现Win32消息 DTM_GETSYSTEMTIME的行为,如 Windows SDK所述。 在 GetTime的MFC实现,可以使用 COleDateTimeCTime 选件类,也可以使用 SYSTEMTIME 结构,存储时间信息。

在第二个和第三个版本的返回值 DWORD,上面,如 NMDATETIMECHANGE 结构成员 dwFlags所示指示日期和时间选择器控件是否设置为“没有日期”状态。 如果返回的值等于 GDT_NONE,控件设置为“没有日期”状态,并使用 DTS_SHOWNONE 样式。 如果返回的值等于 GDT_VALID,系统时在目标位置成功存储。

示例

void CDateTimeDlg::OnBnClickedTimebutton()
{
   // get as a CTime
   CTime timeTime;
   DWORD dwResult = m_DateTimeCtrl.GetTime(timeTime);
   if (dwResult == GDT_VALID)
   {
      // the user checked the box and specified data
      CString str;

      // is it a time-only control, or a date-only control?
      if ((m_DateTimeCtrl.GetStyle() & DTS_TIMEFORMAT) == DTS_TIMEFORMAT)
         str = timeTime.Format(_T("%X"));
      else
         str = timeTime.Format(_T("%x"));
      AfxMessageBox(str);
   }
   else
   {
      // the user unmarked the "none" box
      AfxMessageBox(_T("Time not set!"));
   }

   // Calling as SYSTIME is much the same, but calling for a COleDateTime
   // has us test the state of the COleDateTime object for validity to 
   // see if the user did or didn't check the "none" box.
}

要求

Header: afxdtctl.h

请参见

参考

CDateTimeCtrl选件类

层次结构图

CDateTimeCtrl::SetTime