ctime
, _ctime32
, _ctime64
, _wctime
, _wctime32
, _wctime64
時刻値を文字列に変換し、ローカルの時間帯設定に合わせて調整します。 これらの関数のセキュリティを強化したバージョンを使用できます。「ctime_s
、_ctime32_s
、_ctime64_s
、_wctime_s
、_wctime32_s
、_wctime64_s
」を参照してください。
構文
char *ctime( const time_t *sourceTime );
char *_ctime32( const __time32_t *sourceTime );
char *_ctime64( const __time64_t *sourceTime );
wchar_t *_wctime( const time_t *sourceTime );
wchar_t *_wctime32( const __time32_t *sourceTime );
wchar_t *_wctime64( const __time64_t *sourceTime );
パラメーター
sourceTime
変換する格納された時間へのポインター。
戻り値
文字列結果へのポインター。 NULL
は、次の場合に返されます。
sourceTime
が 1970 年 1 月 1 日の深夜 0 時 (協定世界時) よりも前の日付を示している場合。_ctime32
または_wctime32
、sourceTime
UTC の 2038 年 1 月 18 日 23:59:59 以降の日付を表します。_ctime64
または_wctime64
、sourceTime
UTC の 3000 年 12 月 31 日 23:59:59 以降の日付を表します。
ctime
は _ctime64
と評価されるインライン関数であり、time_t
は __time64_t
と等価です。 コンパイラが time_t
を古い 32 ビットの time_t
として解釈するよう強制する必要がある場合には、 _USE_32BIT_TIME_T
を定義します。 このマクロは次の ctime
値に評価されます _ctime32
。 アプリケーションは 2038 年 1 月 18 日以降に失敗する可能性があり、64 ビット プラットフォームでは許可されないため、使用しないことをお勧めします。
解説
この関数は ctime
、値として格納された時間値を time_t
文字列に変換します。 この値は sourceTime
通常、1970 年 1 月 1 日の午前 0 時 (00:00:00)、協定世界時 (UTC) から経過した秒数を返す呼び出し time
から取得されます。 戻り値には厳密に 26 文字が含まれ、次の形式になります。
Wed Jan 02 02:03:55 1980\n\0
24 時間制が使用されます。 すべてのフィールドには一定の幅があります。 文字列の最後の 2 つの位置には、改行文字 ('\n') と null 文字 ('\0') が入ります。
変換された文字列も、ローカル タイム ゾーンの設定に従って調整されます。 ローカル時刻の構成の詳細については、,,およびlocaltime
関数をtime
_ftime
参照してください。 タイム ゾーン環境とグローバル変数の定義の詳細については、関数を _tzset
参照してください。
ctime
を呼び出すと、gmtime
関数と localtime
関数により使用される、静的に割り当てられた 1 つのバッファーが変更されます。 これらのルーチンを呼び出すたびに、前の呼び出しの結果は破棄されます。 ctime
は、asctime
関数と静的バッファーを共有します。 そのため、ctime
を呼び出すと、asctime
、localtime
、または gmtime
を以前に呼び出した結果が破棄されます。
_wctime
と _wctime64
は ctime
と _ctime64
のワイド文字バージョンです。ワイド文字列のポインターを返します。 それ以外では、_ctime64
、_wctime
、_wctime64
の動作は ctime
と同じです。
これらの関数では、パラメーターの検証が行われます。 null ポインターの場合sourceTime
、または値が負の場合、「パラメーターのsourceTime
検証」で説明されているように、これらの関数は無効なパラメーター ハンドラーを呼び出します。 実行の継続が許可された場合、関数は NULL
を返し、errno
を EINVAL
に設定します。
既定では、この関数のグローバル状態の適用対象は、アプリケーションになります。 この動作を変更するには、「CRT のグローバル状態」を参照してください。
汎用テキスト ルーチンのマップ
TCHAR.H のルーチン | _UNICODE と _MBCS が定義されていない |
_MBCS が定義されている |
_UNICODE が定義されている |
---|---|---|---|
_tctime |
ctime |
ctime |
_wctime |
_tctime32 |
_ctime32 |
_ctime32 |
_wctime32 |
_tctime64 |
_ctime64 |
_ctime64 |
_wctime64 |
必要条件
ルーチンによって返される値 | 必須ヘッダー |
---|---|
ctime |
<time.h> |
_ctime32 |
<time.h> |
_ctime64 |
<time.h> |
_wctime |
<time.h> または <wchar.h> |
_wctime32 |
<time.h> または <wchar.h> |
_wctime64 |
<time.h> または <wchar.h> |
互換性の詳細については、「 Compatibility」を参照してください。
例
// crt_ctime64.c
// compile with: /W3
/* This program gets the current
* time in _time64_t form, then uses ctime to
* display the time in string form.
*/
#include <time.h>
#include <stdio.h>
int main( void )
{
__time64_t ltime;
_time64( <ime );
printf( "The time is %s\n", _ctime64( <ime ) ); // C4996
// Note: _ctime64 is deprecated; consider using _ctime64_s
}
The time is Wed Feb 13 16:04:43 2002
関連項目
時間管理
asctime
, _wasctime
ctime_s
, _ctime32_s
, _ctime64_s
, _wctime_s
, _wctime32_s
, _wctime64_s
_ftime
, _ftime32
, _ftime64
gmtime
, _gmtime32
, _gmtime64
localtime
, _localtime32
, _localtime64
time
, _time32
, _time64
フィードバック
https://aka.ms/ContentUserFeedback」を参照してください。
以下は間もなく提供いたします。2024 年を通じて、コンテンツのフィードバック メカニズムとして GitHub の issue を段階的に廃止し、新しいフィードバック システムに置き換えます。 詳細については、「フィードバックの送信と表示