cppreference.com -> 標準 C 時間 & 日付関数 -> 詳細

標準 C 時間 & 日付関数


asctime

文法:

  #include <time.h>
  char *asctime( const struct tm *時間 );

asctime()は時間 構造体で示された時間を以下のフォーマットの文字列に変換する:

   曜日 月 日 時間:分:秒 年\n\0

サンプル:

    Mon Jun 26 12:03:53 2000
関連トピック:
localtime(), gmtime(), time(), ctime()

clock

文法:

  #include <time.h>
  clock_t clock( void );

clock()関数はプログラムの実行を開始してからのプロセッサ時間を返す関数である。得られなかった場合には-1を返す。プロセッサ時間を秒に直すにはCLOCKS_PER_SECONDマクロでこの関数の返値を割ればよい。POSIX準拠のコンパイラであれば、CLOCKS_PER_SECONDの値は常に1,000,000である。

関連トピック:
time(), asctime(), ctime()

ctime

文法:

  #include <time.h>
  char *ctime( const time_t *時間 );

ctime()はカレンダー時間の時間 を以下のフォーマットの文字列に変換する:

    曜日 月 日 時間:分:秒 年\n\0

ctime()は以下の関数呼び出しと同じである

    asctime( localtime( tp ) );
関連トピック:
localtime(), gmtime(), time(), asctime().

difftime

文法:

  #include <time.h>
  double difftime( time_t 時間2, time_t 時間1 );

difftime()は時間2 - 時間1 という計算を秒のオーダーで求める関数である。

関連トピック:
localtime(), gmtime(), time(), asctime()

gmtime

文法:

  #include <time.h>
  struct tm *gmtime( const time_t *時間 );

gmtime()は与えられたグリニッジ標準時刻の時間 を返す関数である。サポートされていない場合にはNULLを返す。 警告!

関連トピック:
localtime(), time(), asctime().

localtime

文法:

  #include <time.h>
  struct tm *localtime( const time_t *時間 );

localtime()はカレンダー時間の時間 をローカル時間に変換する。 警告!

関連トピック:
gmtime(), time(), asctime()

mktime

文法:

  #include <time.h>
  time_t mktime( struct tm *時間 );

mktime()はローカルタイムの時間 をカレンダー時間に変換して返す関数である。エラーがあった場合には-1が返る。

関連トピック:
time(), gmtime(), asctime(), ctime()

strftime

文法:

  #include <time.h>
  size_t strftime( char *文字列バッファ, size_t 最大長, const char *フォーマット, struct tm *時間 );

strftime()は時間 の時間、日時情報を、フォーマット で指定されたフォーマットに従って変換し、文字列バッファ に格納する。文字列バッファの大きさを長さ で指定する。フォーマット に指定する特別な文字は以下の通りである:

コード意味
%aabbreviated weekday name
%Afull weekday name
%babbreviated month name
%Bfull month name
%cthe standard date and time string
%dday of the month, as a number (1-31)
%Hhour, 24 hour format (0-23)
%Ihour, 12 hour format (1-12)
%jday of the year, as a number (1-366)
%mmonth as a number (1-12). Note: some versions of Microsoft Visual C++ may use values that range from 0-11.
%Mminute as a number (0-59)
%plocale's equivalent of AM or PM
%Ssecond as a number (0-59)
%Uweek of the year, sunday as the first day
%wweekday as a decimal (0-6, sunday=0)
%Wweek of the year, monday as the first day
%xstandard date string
%Xstandard time string
%yyear in decimal, without the century (0-99)
%Yyear in decimal, with the century
%Ztime zone name
%%a percent sign

strftime()関数は文字列バッファ に書き込んだ文字数を返す。エラーが発生した場合にはゼロを返す。

関連トピック:
time(), localtime(), gmtime().

time

文法:

  #include <time.h>
  time_t time( time_t *time );

time()は現在の時間を返す関数である。エラーが発生した場合には-1が返される。引数の時間 が与えられた場合には、現在の時刻が時間 に格納される。

関連トピック:
localtime(), gmtime(), strftime(), ctime()