CDateTimeCtrl::GetTime

BOOL GetTime( COleDateTime& timeDest ) const;

DWORD GetTime( CTime& timeDest ) const;

DWORD GetTime( LPSYSTEMTIME pTimeDest ) const;

Return Value

In the first version, nonzero if the time is successfully written to the COleDateTime object; otherwise 0. In the second and third versions, a DWORD value equal to the dwFlag member set in the NMDATETIMECHANGE structure. See the Remarks section below for more information.

Parameters

timeDest

In the first version, a reference to a COleDateTime object that will receive the system time information. In the second version, a reference to a CTime object that will receive the system time information.

pTimeDest

A pointer to the SYSTEMTIME structure to receive the system time information. Must not be NULL.

Remarks

This member function implements the behavior of the Win32 message DTM_GETSYSTEMTIME, as described in the Platform SDK.

In the MFC implementation of GetTime, you can use COleDateTime or CTime classes, or you can use a SYSTEMTIME structure, to store the time information.

The return value DWORD in the second and third versions, above, indicates whether or not the date and time picker control is set to the "no date" status, as indicated in the NMDATETIMECHANGE structure member dwFlags. If the value returned equals GDT_NONE, the control is set to "no date" status, and uses the DTS_SHOWNONE style. If the value returned equals GDT_VALID, the system time is successfully stored in the destination location.

Example

void CDatesDlg::OnButton2() 
{
   // Gain a pointer to the control
   CDateTimeCtrl* pCtrl = (CDateTimeCtrl*) GetDlgItem(IDC_DATETIMEPICKER1);
   ASSERT(pCtrl != NULL);

   // get as a CTime
   CTime timeTime;
   DWORD dwResult = pCtrl->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 ((pCtrl->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.
}

CDateTimeCtrl OverviewClass MembersHierarchy Chart

See Also   CDateTimeCtrl::SetTime