1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241
|
.\" Copyright 2001 walter harms (walter.harms@informatik.uni-oldenburg.de)
.\" and Copyright 2008, Linux Foundation, written by Michael Kerrisk
.\" <mtk.manpages@gmail.com>
.\"
.\" %%%LICENSE_START(VERBATIM)
.\" 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.
.\" %%%LICENSE_END
.\"
.\" Modified, 2001-12-26, aeb
.\" 2008-09-07, mtk, Various rewrites; added an example program.
.\"
.\"*******************************************************************
.\"
.\" This file was generated with po4a. Translate the source file.
.\"
.\"*******************************************************************
.\"
.\" Japanese Version Copyright (c) 2002 NAKANO Takeo
.\" and Copyright (c) 2008, Akihiro MOTOKI all rights reserved.
.\"
.TH GETDATE 3 2014\-06\-13 "" "Linux Programmer's Manual"
.SH 名前
getdate, getdate_r \- 日付と時刻の文字列を要素別の時刻に変換する
.SH 書式
\fB#include <time.h>\fP
.sp
\fBstruct tm *getdate(const char *\fP\fIstring\fP\fB);\fP
.sp
\fBextern int getdate_err;\fP
.sp
\fB#include <time.h>\fP
.sp
\fBint getdate_r(const char *\fP\fIstring\fP\fB, struct tm *\fP\fIres\fP\fB);\fP
.sp
.in -4n
glibc 向けの機能検査マクロの要件 (\fBfeature_test_macros\fP(7) 参照):
.in
.sp
\fBgetdate\fP():
.ad l
.RS 4
_XOPEN_SOURCE\ >=\ 500 || _XOPEN_SOURCE\ &&\ _XOPEN_SOURCE_EXTENDED
.RE
.br
\fBgetdate_r\fP():
.ad l
.RS 4
_GNU_SOURCE
.RE
.ad
.SH 説明
\fBgetdate\fP() 関数は、 \fIstring\fP が指すバッファーに格納された文字列表現の日付と時刻を、 要素別の時刻 (broken\-down
time) に変換する。 要素別の時刻は \fItm\fP 構造体に格納され、この構造体へのポインターが関数の結果として返される。 この \fItm\fP
構造体は静的なメモリー領域にあり、 \fBgetdate\fP() のそれ以降の呼び出しで上書きされるかもされない。
(\fIformat\fP 引き数でフォーマットを指定する) \fBstrptime\fP(3) とは違い、 \fBgetdate\fP() は環境変数
\fBDATEMSK\fP で指定されたフルパス名のファイルに書いてあるフォーマットを用いる。
マッチの際には大文字小文字を区別しない。 パターン中でも変換される文字列中でも、余分な空白文字は無視される。
パターンに指定できる変換指定は、 \fBstrptime\fP(3) のものと同じである。 POSIX.1\-2001
では一つの変換指定が追加で規定されている。
.TP
\fB%Z\fP
タイムゾーンの名前。 glibc では実装されていない。
.LP
\fB%Z\fP が指定された場合、要素別の時刻を格納する構造体は、 指定されたタイムゾーンにおける現在時刻に対応する値で初期化される。
指定されていない場合、この構造体は現在のローカルタイムに対応する 要素別の時刻で初期化される (\fBlocaltime\fP(3)
を呼び出した場合と同じ)。
.LP
曜日だけが指定された場合、 今日または今日以降で、 その曜日に合致する最初の日が採用される。
.LP
(年なしで) 月だけが指定された場合、 今月または今月以降で、 その月に合致する最初の月が採用される。
.LP
時・分・秒がいずれも指定されなかった場合、 現在の時・分・秒が採用される。
.LP
日付の指定がなかったが、時間 (hour) だけ指定された場合は、 現在の時間またはそれ以降で、その指定に合致する最初の時間が採用される。
\fBgetdate_r\fP() は GNU 拡張で \fBgetdate\fP() のリエントラント版を提供している。 \fBgetdate_r\fP()
では、エラーを報告するのにグローバル変数を使用したり、 要素別の時刻を返すのに静的なバッファーを使用したりせず、
エラーを関数の返り値経由で報告し、要素別の時刻を 引き数 \fIres\fP が指し示す呼び出し側で割り当てたバッファーに格納して返す。
.SH 返り値
成功すると、 \fBgetdate\fP() は \fIstruct tm\fP へのポインターを返す。 失敗すると NULL を返し、グローバル変数
\fIgetdate_err\fP に以下に示すエラー番号のいずれか一つを設定する。 \fIerrno\fP の変更については規定されていない。
成功すると、 \fBgetdate_r\fP() は 0 を返す。 失敗すると、以下に示すエラー番号のいずれか一つを返す。
.SH エラー
以下のエラーが、 (\fBgetdate\fP() では) \fIgetdate_err\fP 経由で返され、 (\fBgetdate_r\fP() では)
関数の返り値として返される。
.TP 4n
\fB1\fP
環境変数 \fBDATEMASK\fP が未定義、またはその値が空文字列である。
.TP
\fB2\fP
\fBDATEMSK\fP で指定されたテンプレートファイルを読み込み用にオープンできない。
.TP
\fB3\fP
.\" stat()
ファイルのステータス情報が取得できない。
.TP
\fB4\fP
テンプレートファイルが通常のファイルでない。
.TP
\fB5\fP
テンプレートファイルの読み込み中にエラーが起こった。
.TP
\fB6\fP
.\" Error 6 doesn't seem to occur in glibc
メモリーの割り当てに失敗した (メモリーが足りない)。
.TP
\fB7\fP
入力にマッチしたファイルに、行が含まれていない。
.TP
\fB8\fP
入力指定が正しくない。
.SH 環境変数
.TP
\fBDATEMSK\fP
書式パターンを含むファイル。
.TP
\fBTZ\fP, \fBLC_TIME\fP
\fBstrptime\fP(3) が用いる変数。
.SH 属性
.SS "マルチスレッディング (pthreads(7) 参照)"
\fBgetdate\fP() 関数はスレッドセーフではない。
.LP
\fBgetdate_r\fP() 関数はスレッドセーフである。
.SH 準拠
POSIX.1\-2001.
.SH 注意
POSIX.1\-2001 仕様では、 \fBstrptime\fP(3) については \fB%E\fP や \fB%O\fP
といった修正子を用いた変換指定を規定しているが、 \fBgetdate\fP() についてはこのような修飾子の規定はない。 glibc では、
\fBgetdate\fP() は \fBstrptime\fP(3) を用いて実装されており、 両者では全く同じ変換が両者でサポートされている。
.SH 例
以下のプログラムは、コマンドライン引き数のそれぞれについて \fBgetdate\fP() を呼び出し、それぞれについて返された \fItm\fP
構造体のフィールド値を表示する。 次のシェルセッションは、プログラムの動作例である。
.in +4n
.nf
$\fB TFILE=$PWD/tfile\fP
$\fB echo \(aq%A\(aq > $TFILE \fP # Full name of the day of the week
$\fB echo \(aq%T\(aq >> $TFILE\fP # ISO date (YYYY\-MM\-DD)
$\fB echo \(aq%F\(aq >> $TFILE\fP # Time (HH:MM:SS)
$\fB date\fP
$\fB export DATEMSK=$TFILE\fP
$\fB ./a.out Tuesday \(aq2009\-12\-28\(aq \(aq12:22:33\(aq\fP
Sun Sep 7 06:03:36 CEST 2008
Call 1 ("Tuesday") succeeded:
tm_sec = 36
tm_min = 3
tm_hour = 6
tm_mday = 9
tm_mon = 8
tm_year = 108
tm_wday = 2
tm_yday = 252
tm_isdst = 1
Call 2 ("2009\-12\-28") succeeded:
tm_sec = 36
tm_min = 3
tm_hour = 6
tm_mday = 28
tm_mon = 11
tm_year = 109
tm_wday = 1
tm_yday = 361
tm_isdst = 0
Call 3 ("12:22:33") succeeded:
tm_sec = 33
tm_min = 22
tm_hour = 12
tm_mday = 7
tm_mon = 8
tm_year = 108
tm_wday = 0
tm_yday = 250
tm_isdst = 1
.fi
.in
.SS プログラムのソース
\&
.nf
#define _GNU_SOURCE
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
int
main(int argc, char *argv[])
{
struct tm *tmp;
int j;
for (j = 1; j < argc; j++) {
tmp = getdate(argv[j]);
if (tmp == NULL) {
printf("Call %d failed; getdate_err = %d\en",
j, getdate_err);
continue;
}
printf("Call %d (\e"%s\e") succeeded:\en", j, argv[j]);
printf(" tm_sec = %d\en", tmp\->tm_sec);
printf(" tm_min = %d\en", tmp\->tm_min);
printf(" tm_hour = %d\en", tmp\->tm_hour);
printf(" tm_mday = %d\en", tmp\->tm_mday);
printf(" tm_mon = %d\en", tmp\->tm_mon);
printf(" tm_year = %d\en", tmp\->tm_year);
printf(" tm_wday = %d\en", tmp\->tm_wday);
printf(" tm_yday = %d\en", tmp\->tm_yday);
printf(" tm_isdst = %d\en", tmp\->tm_isdst);
}
exit(EXIT_SUCCESS);
}
.fi
.SH 関連項目
\fBtime\fP(2), \fBlocaltime\fP(3), \fBsetlocale\fP(3), \fBstrftime\fP(3), \fBstrptime\fP(3)
.SH この文書について
この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 3.79 の一部
である。プロジェクトの説明とバグ報告に関する情報は
http://www.kernel.org/doc/man\-pages/ に書かれている。
|