函式
<cwchar>

wcsftime

size_t wcsftime (wchar_t* ptr, size_t maxsize, const wchar_t* format,                 const struct tm* timeptr);
將時間格式化為寬字串
format的內容複製到ptr中,並按照timeptr指定的格式擴充套件其格式標記,限制為maxsize個字元。

這是strftime<ctime>)的寬字元等效函式。

引數

ptr
指向用於存放結果C寬字串的目標陣列的指標。
maxsize
要複製到ptr的最大寬字元數。
format
C寬字串,包含一個格式字串,其規格遵循strftime中的format(有關詳細資訊,請參閱strftime)。
timeptr
指向tm結構的指標,該結構包含一個已分解為各組成部分的日曆時間(請參閱struct tm)。

返回值

如果生成的C寬字串(包括終止的空寬字元)小於maxsize個寬字元,則返回複製到ptr的總字元數(不包括終止的空寬字元)。
否則,返回零,並且陣列的內容不確定。

示例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
/* wcsftime example */
#include <wchar.h>
#include <time.h>

int main ()
{
  time_t rawtime;
  struct tm * timeinfo;
  wchar_t buffer [80];

  time ( &rawtime );
  timeinfo = localtime ( &rawtime );

  wcsftime (buffer,80,L"Now it's %I:%M%p.",timeinfo);
  wprintf (L"%ls\n",buffer);

  return 0;
}

示例輸出

Now it's 04:33PM.


另見