COleDateTimeSpan::Format

產生 COleDateTimeSpan 物件中的格式化字串表示。

CString Format(
   LPCTSTR pFormat 
) const;
CString Format(
   UINT nID 
) const;

參數

  • pFormat
    格式化字串類似格式化字串的 printf 。 格式化程式碼,在一個百分比 (%) 之後簽署,以對應的 COleDateTimeSpan 元件取代。 在格式化字串中的任何其他字元原封不動地複製到傳回的字串。 格式化程式碼的值和 格式 的意義如下所列:

    • %H 小時 (目前的日期

    • %M 分鐘目前時間。

    • %S 秒目前分鐘內

    • %% 百分比符號

    列出的四種格式程式碼上述是格式會接受內的程式碼。

  • nID
    字串格式控制項的資源 ID。

傳回值

包含格式化的日期/時間間隔值的 CString

備註

呼叫這些函式建立 TimeSpan 值為的格式化表示。 如果這個物件 COleDateTimeSpan 狀況是空的,則傳回值為空字串。 如果狀態無效,則傳回字串是由資源 IDS_INVALID_DATETIMESPAN指定。

表單的概要說明這個函式的後面:

  • Format( pFormat )
    這個表單格式化值使用於 printf包含特殊格式程式碼中的百分比符號 (%) 格式字串後。 格式字串會做為參數傳遞至函式。

  • Format( nID )
    這個表單格式化值使用於 printf包含特殊格式程式碼中的百分比符號 (%) 格式字串後。 格式字串是資源。 這個字串資源 ID 傳遞做為參數。

範例

// get the current time
COleDateTime tmStart = COleDateTime::GetCurrentTime();

// waste some time
CString str;
::Sleep(3000);

// get the current time again
COleDateTime tmFinish = COleDateTime::GetCurrentTime();

// find the difference
COleDateTimeSpan tmSpan = tmFinish - tmStart;

// tell the user
str = tmSpan.Format(_T("%S seconds elapsed"));
_tprintf_s(_T("%s\n"), (LPCTSTR) str);

需求

Header: atlcomtime.h

請參閱

參考

COleDateTimeSpan 類別

階層架構圖

COleDateTimeSpan::GetStatus