.\" Copyright 1993 David Metcalfe (david@prism.demon.co.uk) .\" .\" Permission is granted to make and distribute verbatim copies of this .\" manual provided the copyright notice and this permission notice are .\" preserved on all copies. .\" .\" Permission is granted to copy and distribute modified versions of this .\" manual under the conditions for verbatim copying, provided that the .\" entire resulting derived work is distributed under the terms of a .\" permission notice identical to this one. .\" .\" Since the Linux kernel and libraries are constantly changing, this .\" manual page may be incorrect or out-of-date. The author(s) assume no .\" responsibility for errors or omissions, or for damages resulting from .\" the use of the information contained herein. The author(s) may not .\" have taken the same level of care in the production of this manual, .\" which is licensed free of charge, as they might when working .\" professionally. .\" .\" Formatted or processed versions of this manual, if unaccompanied by .\" the source, must acknowledge the copyright and authors of this work. .\" .\" References consulted: .\" Linux libc source code .\" Lewine's _POSIX Programmer's Guide_ (O'Reilly & Associates, 1991) .\" 386BSD man pages .\" Modified Sat Jul 24 19:49:27 1993 by Rik Faith (faith@cs.unc.edu) .\" Modified Fri Apr 26 12:38:55 MET DST 1996 by Martin Schulze (joey@linux.de) .\" Modified 2001-11-13, aeb .\" Modified 2004-11-16, mtk .\" .\" Japanese Version Copyright (c) 1997 Hiroaki Nagoya .\" all rights reserved. .\" Translated 1997-02-10, Hiroaki Nagoya .\" Updated 1999-09-01, Kentaro Shirakata .\" Updated 2001-10-15, Kentaro Shirakata .\" Updated 2001-12-13, Kentaro Shirakata .\" Updated 2002-01-03, Kentaro Shirakata .\" Updated 2005-02-24, Akihiro MOTOKI .\" Updated 2008-04-04, Akihiro MOTOKI , LDP v2.79 .\" Updated 2008-08-08, Akihiro MOTOKI , LDP v3.05 .\" Updated 2008-11-10, Akihiro MOTOKI , LDP v3.13 .\" .\"WORD: Coordinated Univarsal Time 協定世界時 .\"WORD: broken-down time 要素別の時刻 .\" .TH CTIME 3 2010-02-25 "" "Linux Programmer's Manual" .\"O .SH NAME .SH 名前 .\"O asctime, ctime, gmtime, localtime, mktime, asctime_r, ctime_r, gmtime_r, .\"O localtime_r \- transform date and time to broken-down time or ASCII asctime, ctime, gmtime, localtime, mktime, asctime_r, ctime_r, gmtime_r, localtime_r \- 日付と時刻を要素別の時刻や ASCII に変換する .\"O .SH SYNOPSIS .SH 書式 .nf .B #include .sp .BI "char *asctime(const struct tm *" tm ); .br .BI "char *asctime_r(const struct tm *" tm ", char *" buf ); .sp .BI "char *ctime(const time_t *" timep ); .br .BI "char *ctime_r(const time_t *" timep ", char *" buf ); .sp .BI "struct tm *gmtime(const time_t *" timep ); .br .BI "struct tm *gmtime_r(const time_t *" timep ", struct tm *" result ); .sp .BI "struct tm *localtime(const time_t *" timep ); .br .BI "struct tm *localtime_r(const time_t *" timep ", struct tm *" result ); .sp .BI "time_t mktime(struct tm *" tm ); .fi .sp .in -4n .\"O Feature Test Macro Requirements for glibc (see .\"O .BR feature_test_macros (7)): glibc 向けの機能検査マクロの要件 .RB ( feature_test_macros (7) 参照): .in .ad l .sp .BR asctime_r (), .BR ctime_r (), .BR gmtime_r (), .BR localtime_r (): .RS _POSIX_C_SOURCE\ >=\ 1 || _XOPEN_SOURCE || _BSD_SOURCE || _SVID_SOURCE || _POSIX_SOURCE .RE .ad .\"O .SH DESCRIPTION .SH 説明 .\"O The .\"O .BR ctime (), .\"O .BR gmtime () .\"O and .\"O .BR localtime () .\"O functions all take .\"O an argument of data type \fItime_t\fP which represents calendar time. .\"O When interpreted as an absolute time value, it represents the number of .\"O seconds elapsed since the Epoch, 1970-01-01 00:00:00 +0000 (UTC). 関数 .BR ctime (), .BR gmtime (), .BR localtime () は \fItime_t\fP 型のカレンダー時刻を引き数にとる。 引き数が絶対値として解釈される場合は、時刻紀元 (Epoch; 1970-01-01 00:00:00 +0000 (UTC)) からの経過秒数と解釈される。 .PP .\"O The .\"O .BR asctime () .\"O and .\"O .BR mktime () .\"O functions both take an argument .\"O representing broken-down time which is a representation .\"O separated into year, month, day, etc. 関数 .BR asctime () と .BR mktime () は 年・月・日などに分離された要素別の時刻を引き数とする。 .PP .\"O Broken-down time is stored .\"O in the structure \fItm\fP which is defined in \fI\fP as follows: 要素別の時刻は \fI\fP で以下のように定義されている \fItm\fP 構造体に保持される。 .sp .in +4n .nf struct tm { .\"O int tm_sec; /* seconds */ .\"O int tm_min; /* minutes */ .\"O int tm_hour; /* hours */ .\"O int tm_mday; /* day of the month */ .\"O int tm_mon; /* month */ .\"O int tm_year; /* year */ .\"O int tm_wday; /* day of the week */ .\"O int tm_yday; /* day in the year */ .\"O int tm_isdst; /* daylight saving time */ int tm_sec; /* 秒 */ int tm_min; /* 分 */ int tm_hour; /* 時間 */ int tm_mday; /* 日 */ int tm_mon; /* 月 */ int tm_year; /* 年 */ int tm_wday; /* 曜日 */ int tm_yday; /* 年内通算日 */ int tm_isdst; /* 夏時間 */ }; .fi .in .PP .\"O The members of the \fItm\fP structure are: \fItm\fP 構造体のメンバーは以下の通り: .TP 10 .I tm_sec .\"O The number of seconds after the minute, normally in the range 0 to 59, .\"O but can be up to 60 to allow for leap seconds. 秒数、ふつうは 0 から 59 までの値、 しかし閏秒のため 60 までの値は許される。 .TP .I tm_min .\"O The number of minutes after the hour, in the range 0 to 59. 分数、0 から 59 までの値。 .TP .I tm_hour .\"O The number of hours past midnight, in the range 0 to 23. 真夜中からの通算時間、0 から 23 までの値。 .TP .I tm_mday .\"O The day of the month, in the range 1 to 31. 月はじめからの日数、1 から 31 までの値。 .TP .I tm_mon .\"O The number of months since January, in the range 0 to 11. 1月からの通算月数、0 から 11 までの値。 .TP .I tm_year .\"O The number of years since 1900. 1900 年からの通算年数。 .TP .I tm_wday .\"O The number of days since Sunday, in the range 0 to 6. 日曜日からの通算日数(曜日)。0 から 6 までの値。 .TP .I tm_yday .\"O The number of days since January 1, in the range 0 to 365. 1 月 1 日からの通算日数、0 から 365 までの値。 .TP .I tm_isdst .\"O A flag that indicates whether daylight saving time is in effect at the .\"O time described. .\"O The value is positive if daylight saving time is in .\"O effect, zero if it is not, and negative if the information is not .\"O available. 夏時間が有効かどうかのフラグ。 正の値ならば夏時間は有効になり、0 ならば無効、負の値ならばこの情報には 意味がない。 .PP .\"O The call .\"O .BI ctime( t ) .\"O is equivalent to .\"O .BI asctime(localtime( t )) \fR. .\"O It converts the calendar time \fIt\fP into a .\"O null-terminated string of the form .\"O .sp .\"O .RS .\"O "Wed Jun 30 21:49:08 1993\\n" .\"O .RE .\"O .sp .BI ctime( t ) 関数は、 .BI asctime(localtime( t )) と等価である。 カレンダー時刻 \fIt\fP を .sp .RS "Wed Jun 30 21:49:08 1993\\n" .RE .sp という形式の NULL 終端された文字列へ変換する。 .\"O The abbreviations for the days of the week are "Sun", "Mon", "Tue", "Wed", .\"O "Thu", "Fri", and "Sat". .\"O The abbreviations for the months are "Jan", .\"O "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", and .\"O "Dec". .\"O The return value points to a statically allocated string which .\"O might be overwritten by subsequent calls to any of the date and time .\"O functions. .\"O The function also sets the external .\"O variables \fItzname\fP, \fItimezone\fP, and \fIdaylight\fP (see .\"O .BR tzset (3)) .\"O with information about the current timezone. 曜日の略称は "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" である。 月の略称は "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" である。 返り値は、静的 (static) に割り当てられた文字列へのポインタである。 この文字列は、日付・時刻関数のいずれかが呼び出されると上書きされることがある。 またこの関数は大域変数 \fItzname\fP, \fItimezone\fP, \fIdaylight\fP に現在のタイムゾーンの情報を設定する .RB ( tzset (3) 参照)。 .\"O The reentrant version .\"O .BR ctime_r () .\"O does the same, but stores the .\"O string in a user-supplied buffer .\"O which should have room for at least 26 bytes. .\"O It need not .\"O set \fItzname\fP, \fItimezone\fP, and \fIdaylight\fP. リエントラント版である .BR ctime_r () も同様だが、 文字列はユーザーが用意したバッファに格納される。バッファのサイズは 少なくとも 26 バイト以上でなければならない。 この関数は \fItzname\fP, \fItimezone\fP, and \fIdaylight\fP を設定する必要はない。 .PP .\"O The .\"O .BR gmtime () .\"O function converts the calendar time \fItimep\fP to .\"O broken-down time representation, expressed in Coordinated Universal Time .\"O (UTC). .\"O It may return NULL when the year does not fit into an integer. 関数 .BR gmtime () は、カレンダー時刻 \fItimep\fP を 協定世界時 (UTC) での要素別の時刻へ変換する。 年が整数型に収まらない場合、NULL を返す。 .\"O The return value points to a statically allocated struct which might be .\"O overwritten by subsequent calls to any of the date and time functions. 返り値は静的に確保された構造体を指しており、この後で 日付や時刻に関する関数のいずれかが呼び出されると 上書きされる可能性がある。 .\"O The .\"O .BR gmtime_r () .\"O function does the same, but stores the data in a .\"O user-supplied struct. .BR gmtime_r () も同様だが、 データはユーザーが用意した構造体に格納される。 .PP .\"O The .\"O .BR localtime () .\"O function converts the calendar time \fItimep\fP to .\"O broken-down time representation, .\"O expressed relative to the user's specified timezone. .\"O The function acts as if it called .\"O .BR tzset (3) .\"O and sets the external variables \fItzname\fP with .\"O information about the current timezone, \fItimezone\fP with the difference .\"O between Coordinated Universal Time (UTC) and local standard time in .\"O seconds, and \fIdaylight\fP to a nonzero value if daylight savings .\"O time rules apply during some part of the year. 関数 .BR localtime () は、カレンダー時刻 \fItimep\fP を ユーザが指定したタイムゾーンでの時刻要素別の表現へ変換する。 この関数は .BR tzset (3) を呼び出したかのように振舞い、 大域変数 \fItzname\fP に現在のタイムゾーンの情報を設定する。 また、\fItimezone\fP に協定世界時 (UTC) とローカル標準時との 時差の秒数を設定し、 一年の一部で夏時間が適用される場合は \fIdaylight\fP に 0 が設定される。 .\"O The return value points to a statically allocated struct which might be .\"O overwritten by subsequent calls to any of the date and time functions. 返り値は静的に確保された構造体を指しており、この後で 日付や時刻に関する関数のいずれかが呼び出されると 上書きされる可能性がある。 .\"O The .\"O .BR localtime_r () .\"O function does the same, but stores the data in a .\"O user-supplied struct. .\"O It need not set \fItzname\fP, \fItimezone\fP, and \fIdaylight\fP. .BR localtime_r () も同様だが、 データはユーザーが用意した構造体に格納される。 この関数は \fItzname\fP, \fItimezone\fP, and \fIdaylight\fP を設定する必要はない。 .PP .\"O The .\"O .BR asctime () .\"O function converts the broken-down time value .\"O \fItm\fP into a null-terminated string with the same format as .\"O .BR ctime (). .\"O The return value points to a statically allocated string which might be .\"O overwritten by subsequent calls to any of the date and time functions. 関数 .BR asctime () は、要素別の時刻 \fItm\fP を .BR ctime () と同じ形式の NULL 終端された文字列へ変換する。 返り値は静的に割り当てられた文字列へのポインタである。この文字列は、 日付・時刻関数のいずれかが呼び出されると上書きされることがある。 .\"O The .\"O .BR asctime_r () .\"O function does the same, but stores the string in .\"O a user-supplied buffer which should have room for at least 26 bytes. リエントラント版である .BR asctime_r () も同様だが、 文字列はユーザーが用意したバッファに格納される。バッファのサイズは 少なくとも 26 バイト以上でなければならない。 .PP .\"O The .\"O .BR mktime () .\"O function converts a broken-down time structure, expressed .\"O as local time, to calendar time representation. .\"O The function ignores .\"O the values supplied by the caller in the .\"O .I tm_wday .\"O and .\"O .I tm_yday .\"O fields. .\"O The value specified in the .\"O .I tm_isdst .\"O field informs .\"O .BR mktime () .\"O whether or not daylight saving time (DST) .\"O is in effect for the time supplied in the .\"O .I tm .\"O structure: .\"O a positive value means DST is in effect; .\"O zero means that DST is not in effect; .\"O and a negative value means that .\"O .BR mktime () .\"O should (use timezone information and system databases to) .\"O attempt to determine whether DST is in effect at the specified time. 関数 .BR mktime () は、(ローカルタイムで記述されている) 要素別の時刻を カレンダー時刻へ変換する。この際、呼び出し元がフィールド .I tm_wday と .I tm_yday で指定した値は無視される。 .BR mktime () は、フィールド .I tm_isdst で指定された値により、 .I tm 構造体で渡された時刻で夏時間 (daylight saving time; DST) が有効になって いるかを知る。 正の値は夏時間が有効であることを意味する。 負の値であれば、 .BR mktime () は (タイムゾーン情報とシステムのデータベースを使って) 指定された時刻で夏時間が有効かどうかを判断する必要があることを意味する。 .\"O The .\"O .BR mktime () .\"O function modifies the fields of the .\"O .IR tm .\"O structure as follows: .\"O .I tm_wday .\"O and .\"O .I tm_yday .\"O are set to values determined from the contents of the other fields; .BR mktime () は .I tm 構造体の各フィールドを以下のように修正する。 .I tm_wday と .I tm_yday には他のフィールドの内容から求めた値を設定する。 .\"O if structure members are outside their valid interval, they will be .\"O normalized (so that, for example, 40 October is changed into 9 November); .\"O .I tm_isdst .\"O is set (regardless of its initial value) .\"O to a positive value or to 0, respectively, .\"O to indicate whether DST is or is not in effect at the specified time. 構造体の要素が有効な範囲にない場合、正規化される (例えば、10 月 40 日は 11 月 9 日に変更される)。 .I tm_isdst には (最初の値にかかわらず) 正の値か 0 が設定される。 正の値は指定された時間で夏時間が有効であることを示し、 0 は無効であることを示す。 .\"O Calling .\"O .BR mktime () .\"O also sets the external variable \fItzname\fP with .\"O information about the current timezone. 関数 .BR mktime () を呼び出すと、 大域変数 \fItzname\fP が現在のタイムゾーンに設定される。 .\"O If the specified broken-down .\"O time cannot be represented as calendar time (seconds since the Epoch), .\"O .BR mktime () .\"O returns .\"O .I (time_t)\ \-1 .\"O and does not alter the .\"O members of the broken-down time structure. 要素別の時刻をカレンダー時刻 (紀元 (Epoch) からの秒数) で表現できない場合、 .BR mktime () は .I (time_t)\ (-1) を返し、要素別の時刻の構造体メンバーを変更しない。 .\"O .SH "RETURN VALUE" .SH 返り値 .\"O Each of these functions returns the value described, or NULL .\"O (\-1 in case of .\"O .BR mktime ()) .\"O in case an error was detected. 各関数はそれぞれ前述した値を返す。エラーの場合は NULL .RB ( mktime () では \-1) を返す。 .SH 準拠 .\"O POSIX.1-2001. .\"O C89 and C99 specify .\"O .BR asctime (), .\"O .BR ctime (), .\"O .BR gmtime (), .\"O .BR localtime (), .\"O and .\"O .BR mktime (). POSIX.1-2001. C89 と C99 では .BR asctime (), .BR ctime (), .BR gmtime (), .BR localtime (), .BR mktime () が規定されている。 .\"O POSIX.1-2008 marks .\"O .BR asctime (), .\"O .BR asctime_r (), .\"O .BR ctime (), .\"O and .\"O .BR ctime_r () .\"O as obsolete, .\"O recommending the use of .\"O .BR strftime (3) .\"O instead. POSIX.1-2008 は、 .BR asctime (), .BR asctime_r (), .BR ctime (), .BR ctime_r () を廃止予定としている。 代わりに、 .BR strftime (3) の使用が推奨されている。 .\"O .SH NOTES .SH 注意 .\"O The four functions .\"O .BR asctime (), .\"O .BR ctime (), .\"O .BR gmtime () .\"O and .\"O .BR localtime () .\"O return a pointer to static data and hence are not thread-safe. .BR asctime (), .BR ctime (), .BR gmtime (), .BR localtime () の 4 つの関数は静的データへのポインタを返すので、スレッドセーフではない。 .\"O Thread-safe versions .\"O .BR asctime_r (), .\"O .BR ctime_r (), .\"O .BR gmtime_r () .\"O and .\"O .BR localtime_r () .\"O are specified by SUSv2, and available since libc 5.2.5. これらの関数のスレッドセーフ版である .BR asctime_r (), .BR ctime_r (), .BR gmtime_r (), .BR localtime_r () は SUSv2 で規定されており、 libc 5.2.5 以降で利用できる。 .\"O POSIX.1-2001 says: .\"O "The .\"O .BR asctime (), .\"O .BR ctime (), .\"O .BR gmtime (), .\"O and .\"O .BR localtime () .\"O functions shall return values in one of two static objects: .\"O a broken-down time structure and an array of type .\"O .IR char . .\"O Execution of any of the functions may overwrite the information returned .\"O in either of these objects by any of the other functions." .\"O This can occur in the glibc implementation. POSIX.1-2001 では、「関数 .BR asctime (), .BR ctime (), .BR gmtime (), .BR localtime () は、要素別の時刻の構造体か .I char 型の配列かのどちらかの静的オブジェクトを返すものとする。 これらの関数のいずれかを実行すると、他の関数のどれかがこれらの 静的オブジェクトのどちらかに格納して返した情報が上書きされるかも しれない。」となっている。 このことは glibc の実装で起こりうる。 .LP .\"O In many implementations, including glibc, a 0 in .\"O .I tm_mday .\"O is interpreted as meaning the last day of the preceding month. glibc を含む多くの実装では、 .I tm_mday に 0 を指定すると前月の最終日を意味していると解釈される。 .LP .\"O The glibc version of \fIstruct tm\fP has additional fields .\"O .sp .\"O .RS .\"O .nf .\"O long tm_gmtoff; /* Seconds east of UTC */ .\"O const char *tm_zone; /* Timezone abbreviation */ .\"O .fi .\"O .RE .\"O .sp .\"O defined when .\"O .B _BSD_SOURCE .\"O was set before including .\"O .IR . glibc では、 .I がインクルードされる前に .B _BSD_SOURCE が定義されると、 \fIstruct tm\fP に以下のフィールドが追加される。 .sp .RS .nf long tm_gmtoff; /* Seconds east of UTC */ const char *tm_zone; /* Timezone abbreviation */ .fi .RE .sp .\"O This is a BSD extension, present in 4.3BSD-Reno. これは BSD 拡張であり、4.3BSD-Reno から現れた。 .\"O According to POSIX.1-2004, .\"O .BR localtime () .\"O is required to behave as though .\"O .BR tzset (3) .\"O was called, while .\"O .BR localtime_r () .\"O does not have this requirement. .\"O .\" See http://thread.gmane.org/gmane.comp.time.tz/2034/ .\"O For portable code .\"O .BR tzset (3) .\"O should be called before .\"O .BR localtime_r (). POSIX.1-2004 によると、 .BR localtime () はあたかも .BR tzset (3) が呼ばれたかのように振舞うことが要求されているが、 .BR localtime_r () にはこの要件はない。 .\" http://thread.gmane.org/gmane.comp.time.tz/2034/ を参照。 移植性が必要なコードでは、 .BR localtime_r () の前に .BR tzset (3) を呼び出しておくべきである。 .\"O .SH "SEE ALSO" .SH 関連項目 .BR date (1), .BR gettimeofday (2), .BR time (2), .BR utime (2), .BR clock (3), .BR difftime (3), .BR strftime (3), .BR strptime (3), .BR timegm (3), .BR tzset (3), .BR time (7)