asctime_s、wasctime_s

提供: RAD Studio
Asctime s、wasctime sから転送)
移動先: 案内検索

Time.h:インデックス への移動


ヘッダー ファイル

time.h

カテゴリ

日付/時刻ルーチン

プロトタイプ

errno_t asctime_s(char *s, rsize_t maxsize, const struct tm *tmPtr);
errno_t wasctime_s(wchar_t *s, rsize_t maxsize, const struct tm *tmPtr);

説明

asctime の代わりとなるもので、セキュリティ機能が強化されています。

asctime_s は日付と時刻を ASCII に変換します。

wasctime_s は日付と時刻を wchar_t 文字列に変換します。

asctime_swasctime_s は、構造体に格納された時刻を、次の形式の 26 文字の(ワイド)文字列に変換します。

Mon Nov 21 11:31:54 1983\n\0

すべてのフィールドは固定幅です。 出力文字列の曜日およびは次のように対応します。

tm パラメータ/有効な値の範囲/出力

tm.mon(月)/0-11/0=Jan、1=Feb など

tm.day(曜日)/0-6/0=Sun、1=Mon など

実行時制約違反が発生した場合、s[0] には NULL が設定されます。

戻り値

asctime_swasctime_s は、成功すればゼロを、成功しなければゼロ以外を返します。

#include <string.h>
#include <time.h>
#include <stdio.h>
int main(void)
{
  struct tm t;
  char str[80];
  /* Sample loading of tm structure  */
  t.tm_sec    = 1;  /* Seconds */
  t.tm_min    = 30; /* Minutes */
  t.tm_hour   = 9;  /* Hour */
  t.tm_mday   = 22; /* Day of the Month  */
  t.tm_mon    = 11; /* Month */
  t.tm_year   = 56; /* Year - does not include century */
  t.tm_wday   = 4;  /* Day of the week  */
  t.tm_yday   = 0;  /* Does not show in asctime */
  t.tm_isdst  = 0;  /* Is Daylight SavTime; does not show in asctime */
  /* Converts structure to null-terminated string */
  asctime_s(str, 50, &t);
  printf("%s\n", str);
  return 0;
}

移植性

POSIX Win32 ANSI C ANSI C++

asctime_s

+

+

+

+

wasctime_s

+

関連項目