.\" 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 .\" GNU texinfo documentation on glibc date/time functions. .\" Modified Sat Jul 24 18:03:44 1993 by Rik Faith (faith@cs.unc.edu) .\" Applied fix by Wolfgang Franke, aeb, 961011 .\" Corrected return value, aeb, 970307 .\" Added Single UNIX Spec conversions and %z, aeb/esr, 990329. .\" 2005-11-22 mtk, added Glibc Notes covering optional 'flag' and .\" 'width' components of conversion specifications. .\" .\" Japanese Version Copyright (c) 2000 HANATAKA Shinya .\" all rights reserved. .\" Translated 2000-10-10, HANATAKA Shinya .\" Updated 2002-01-09, Kentaro Shirakata .\" Updated 2002-01-14, Akihiro MOTOKI .\" Updated 2005-02-26, Akihiro MOTOKI .\" Updated 2005-04-17, Akihiro MOTOKI .\" Updated 2005-12-05, Akihiro MOTOKI, LDP v2.16 .\" Updated 2010-04-18, Akihiro MOTOKI, LDP v3.24 .\" .\"WORD: conversion specifier 変換指定文字 .\"WORD: conversion specification 変換指定 .\"WORD: modifier 修飾子 .\"WORD: broken-down time 要素別の(時刻) .\"WORD: Single UNIX Specification 統一 UNIX 規格 .\"WORD: ISO\ 8601 week-based ISO\ 8601 の週単位表記 .\" .TH STRFTIME 3 2010-01-17 "GNU" "Linux Programmer's Manual" .SH 名前 .\"O strftime \- format date and time strftime \- 日付および時刻の文字列への変換 .SH 書式 .nf .B #include .sp .BI "size_t strftime(char *" s ", size_t " max ", const char *" format , .BI " const struct tm *" tm ); .fi .SH 説明 .\"O The .\"O .BR strftime () .\"O function formats the broken-down time \fItm\fP .\"O according to the format specification \fIformat\fP and places the .\"O result in the character array \fIs\fP of size \fImax\fP. .BR strftime () 関数 は、要素別の時刻 \fItm\fP の内容を \fIformat\fP で指定された書式指定にしたがって変換し、 長さ \fImax\fP の文字列 \fIs\fP に書き込む。 .\" FIXME POSIX says: Local timezone information is used as though .\" strftime() called tzset(). But this doesn't appear to be the case .PP .\"O The format specification is a null-terminated string and may contain .\"O special character sequences called .\"O .IR "conversion specifications", .\"O each of which is introduced by a \(aq%\(aq character and terminated by .\"O some other character known as a .\"O .IR "conversion specifier character". .\"O All other character sequences are .\"O .IR "ordinary character sequences". 書式指定は NULL 終端された文字列であり、 「変換指定 (conversion specification)」と呼ばれる特別な文字列を 含まることができる。 各々の変換指定は \(aq%\(aq 文字で始まり、 「変換指定文字 (conversion specifier character)」と呼ばれる 何らか他の文字で終端される。上記以外の全ての文字列は 「通常の文字列 (ordinary character sequence)」となる。 .PP .\"O The characters of ordinary character sequences (including the null byte) .\"O are copied verbatim from \fIformat\fP to \fIs\fP. However, the characters .\"O of conversion specifications are replaced as follows: (NULL バイトも含む) 通常の文字列内の文字は、 そのまま \fIformat\fP から \fIs\fP にコピーされる。 一方、変換指定の文字は以下のように置換される。 .TP .B %a .\"O The abbreviated weekday name according to the current locale. 現在のロケールにおける曜日の省略名。 .TP .B %A .\"O The full weekday name according to the current locale. 現在のロケールにおける曜日の完全な名前。 .TP .B %b .\"O The abbreviated month name according to the current locale. 現在のロケールにおける月の省略名。 .TP .B %B .\"O The full month name according to the current locale. 現在のロケールにおける月の完全な名前。 .TP .B %c .\"O The preferred date and time representation for the current locale. 現在のロケールにおいて一般的な日付・時刻の表記。 .TP .B %C .\"O The century number (year/100) as a 2-digit integer. (SU) 世紀 (西暦年の上 2 桁)。 (SU) .TP .B %d .\"O The day of the month as a decimal number (range 01 to 31). 月内通算日 (10 進数表記) (01-31)。 .TP .B %D .\"O Equivalent to .\"O .BR %m/%d/%y . .\"O (Yecch \(em for Americans only. .\"O Americans should note that in other countries .\"O .B %d/%m/%y .\"O is rather common. .\"O ambiguous and should not be used.) (SU) .B %m/%d/%y と等価。(うえっ、アメリカ専用だ。アメリカ以外の国では .B %d/%m/%y の方が一般的だ。紛らわしいので、使用すべきではない。) (SU) .TP .B %e .\"O Like .\"O .BR %d , .\"O the day of the month as a decimal number, but a leading .\"O zero is replaced by a space. (SU) .B %d と同様に月内通算日を 10 進数で表現するが、 1 桁の場合 10 の位にゼロを置かずスペースを置く。(SU) .TP .B %E .\"O Modifier: use alternative format, see below. (SU) 別形式を使用する際の修飾子。下記参照。 (SU) .TP .B %F .\"O Equivalent to .\"O .B %Y-%m-%d .\"O (the ISO\ 8601 date format). (C99) .B %Y-%m-%d と等価 (ISO\ 8601 形式の日付フォーマット)。 (C99) .TP .B %G .\"O The ISO\ 8601 week-based year (see NOTES) with century as a decimal number. .\"O The 4-digit year corresponding to the ISO week number (see .\"O .BR %V ). .\"O This has the same format and value as .\"O .BR %Y , .\"O except that if the ISO week number belongs to the previous or next year, .\"O that year is used instead. (TZ) ISO\ 8601 週単位表記の年 (week-based year; 「注意」の節を参照)。 世紀も 10 進数で表す。 ISO 週番号 .RB ( %V を参照) に対応した 4 桁の西暦年。 これは基本的には .B %Y と同じ形式だが、ISO 週数が前年や翌年になる 場合にはその年が使用される点が異なる。(TZ) .TP .B %g .\"O Like .\"O .BR %G , .\"O but without century, that is, with a 2-digit year (00-99). (TZ) .B %G と同様。但し、世紀を含まず下 2 桁のみを表示 (00-99)。 (TZ) .TP .B %h .\"O Equivalent to .\"O .BR %b . .\"O (SU) .B %b と等価 (SU) .TP .B %H .\"O The hour as a decimal number using a 24-hour clock (range 00 to 23). 24 時間表記での時 (hour)。 (00-23) .TP .B %I .\"O The hour as a decimal number using a 12-hour clock (range 01 to 12). 12 時間表記での時 (hour)。 (01-12) .TP .B %j .\"O The day of the year as a decimal number (range 001 to 366). 年の初めから通算の日数。 (001-366) .TP .B %k .\"O The hour (24-hour clock) as a decimal number (range 0 to 23); .\"O single digits are preceded by a blank. .\"O (See also .\"O .BR %H .) .\"O (TZ) 24 時間表記での時 (0-23)。 1 桁の場合には前にゼロでなくスペースが置かれる。 .RB ( %H も参照) (TZ) .TP .B %l .\"O The hour (12-hour clock) as a decimal number (range 1 to 12); .\"O single digits are preceded by a blank. .\"O (See also .\"O .BR %I .) .\"O (TZ) 12 時間表記での時 (0-12)。 1 桁の場合には前にゼロでなくスペースが置かれる。 .RB ( %I も参照) (TZ) .TP .B %m .\"O The month as a decimal number (range 01 to 12). 月 (10 進数表記)。 (01-12) .TP .B %M .\"O The minute as a decimal number (range 00 to 59). 分 (10 進数表記) (00-59) .TP .B %n .\"O A newline character. (SU) 改行。 (SU) .TP .B %O .\"O Modifier: use alternative format, see below. (SU) 別形式を使用する際の修飾子。以下を参照。(SU) .TP .B %p .\"O Either "AM" or "PM" according to the given time value, or the .\"O corresponding strings for the current locale. .\"O Noon is treated as "PM" and midnight as "AM". 現在のロケールにおける「午前」「午後」に相当する文字列。 英語の場合には "AM" または "PM" となる。 正午は「午後」、真夜中は「午前」として扱われる。 .TP .B %P .\"O Like .\"O .B %p .\"O but in lowercase: "am" or "pm" or a corresponding .\"O string for the current locale. (GNU) .B %p と同様であるが小文字が使用される。 英語の場合には "am" や "pm" となる。(GNU) .TP .B %r .\"O The time in a.m. or p.m. notation. .\"O In the POSIX locale this is equivalent to .\"O .BR "%I:%M:%S %p" . .\"O (SU) 午前・午後形式での時刻。 POSIX ロケールでは .B "%I:%M:%S %p" と等価である。(SU) .TP .B %R .\"O The time in 24-hour notation (\fB%H:%M\fP). (SU) .\"O For a version including the seconds, see .\"O .B %T .\"O below. 24 時間表記での時刻、秒は表示しない .RB ( %H:%M )。 秒を含んだものは以下の .B %T を参照すること。(SU) .TP .B %s .\"O The number of seconds since the Epoch, 1970-01-01 00:00:00 +0000 (UTC). (TZ) 紀元 (Epoch; 1970-01-01 00:00:00 +0000 (UTC)) からの秒数。 (TZ) .TP .B %S .\"O The second as a decimal number (range 00 to 60). .\"O (The range is up to 60 to allow for occasional leap seconds.) 秒 (10 進数表記) (00-60) (時々ある閏秒に対応するため、値の範囲は 60 までとなっている) .TP .B %t .\"O A tab character. (SU) タブ文字 (SU) .TP .B %T .\"O The time in 24-hour notation (\fB%H:%M:%S\fP). (SU) 24 時間表記の時間 (\fB%H:%M:%S\fP) (SU) .TP .B %u .\"O The day of the week as a decimal, range 1 to 7, Monday being 1. .\"O See also .\"O .BR %w . .\"O (SU) 週の何番目の日 (10 進数表記) か。月曜日を 1 とする (1-7)。 .B %w も参照。(SU) .TP .B %U .\"O The week number of the current year as a decimal number, .\"O range 00 to 53, starting with the first Sunday as the first day .\"O of week 01. .\"O See also .\"O .B %V .\"O and .\"O .BR %W . 年の初めからの通算の週番号 (10 進数表記) (00-53)。 その年の最初の日曜日を、第 1 週の始まりとして計算する。 .B %V と .B %W も参照すること。 .TP .B %V .\"O The ISO\ 8601 week number (see NOTES) of the current year as a decimal number, .\"O range 01 to 53, where week 1 is the first week that has at least .\"O 4 days in the new year. .\"O See also .\"O .B %U .\"O and .\"O .BR %W . .\"O (SU) ISO\ 8601 形式での年の始めからの週番号 (「注意」の節を参照)。 10 進数表記で、01 から 53 の値となる。週番号は、 新しい年が少なくとも 4 日以上含まれる最初の週を 1 として計算する。 .B %U と .B %W も参照のこと。(SU) .TP .B %w .\"O The day of the week as a decimal, range 0 to 6, Sunday being 0. .\"O See also .\"O .BR %u . 週の何番目の日 (10 進数表記) か。日曜日を 0 とする。(0-6)。 .B %u も参照。(SU) .TP .B %W .\"O The week number of the current year as a decimal number, .\"O range 00 to 53, starting with the first Monday as the first day of week 01. 年の初めからの通算の週番号 (10 進数表記) (00-53)。 その年の最初の月曜日を、第 1 週の始まりとして計算する。 .TP .B %x .\"O The preferred date representation for the current locale without the time. 現在のロケールで一般的な日付表記。時刻は含まない。 .TP .B %X .\"O The preferred time representation for the current locale without the date. 現在のロケールで一般的な時刻表記。日付は含まない。 .TP .B %y .\"O The year as a decimal number without a century (range 00 to 99). 西暦の下2桁 (世紀部分を含まない年) (00-99)。 .TP .B %Y .\"O The year as a decimal number including the century. 世紀部分を含めた ( 4 桁の) 西暦年。 .TP .B %z .\"O The .\"O .I +hhmm .\"O or .\"O .I -hhmm .\"O numeric timezone (that is, the hour and minute offset from UTC). (SU) .I +hhmm や .I -hhmm の形式のタイムゾーン (UTC へのオフセット時間)。(SU) .TP .B %Z .\"O The timezone or name or abbreviation. タイムゾーンまたはゾーン名または省略名。 .TP .B %+ .\" Nov 05 -- Not in Linux/glibc, but is in some BSDs (according to .\" their man pages) .\"O The date and time in .\"O .BR date (1) .\"O format. (TZ) .\"O (Not supported in glibc2.) .BR date (1) 形式での日時。(TZ) (glibc2 ではサポートされていない) .TP .B %% .\"O A literal \(aq%\(aq character. \(aq%\(aq 文字。 .PP .\"O Some conversion specifications can be modified by preceding the .\"O conversion specifier character by the .\"O .B E .\"O or .\"O .B O .\"O .I modifier .\"O to indicate that an alternative format should be used. いくつかの変換指定では、変換指定文字の前に .B E や .B O 「修飾子」を置くことによって別書式を使用するように指定することができる。 .\"O If the alternative format or specification does not exist for .\"O the current locale, the behavior will be as if the unmodified .\"O conversion specification were used. (SU) 現在のロケールにおいて別書式が存在しない場合には、 通常の変換指定が使用されたかのように動作する (SU)。 .\"O The Single UNIX Specification mentions .\"O .BR %Ec , .\"O .BR %EC , .\"O .BR %Ex , .\"O .BR %EX , .\"O .BR %Ey , .\"O .BR %EY , .\"O .BR %Od , .\"O .BR %Oe , .\"O .BR %OH , .\"O .BR %OI , .\"O .BR %Om , .\"O .BR %OM , .\"O .BR %OS , .\"O .BR %Ou , .\"O .BR %OU , .\"O .BR %OV , .\"O .BR %Ow , .\"O .BR %OW , .\"O .BR %Oy , .\"O where the effect of the .\"O .B O .\"O modifier is to use .\"O alternative numeric symbols (say, roman numerals), and that of the .\"O E modifier is to use a locale-dependent alternative representation. 統一 UNIX 規格 (Single UNIX Specification) では .BR %Ec , .BR %EC , .BR %Ex , .BR %EX , .BR %Ey , .BR %EY , .BR %Od , .BR %Oe , .BR %OH , .BR %OI , .BR %Om , .BR %OM , .BR %OS , .BR %Ou , .BR %OU , .BR %OV , .BR %Ow , .BR %OW , .BR %Oy , について記述がある。ここで .B O 修飾子は別形式の数値 (ローマ数字とか) を指定するために使用する。 .B E 修飾子はロケール依存の別表現を指定するのに使用する。 (訳注: .B E 修飾子は日本で使用されている「昭和」「平成」 などの元号による年表記を指定する。glibc 2.2 以降でのみ有効) .PP .\"O The broken-down time structure \fItm\fP is defined in \fI\fP. .\"O See also .\"O .BR ctime (3). 要素別の時刻構造体 \fItm\fP の詳細は \fI\fP に定義されている。 .BR ctime (3) も参照すること。 .\"O .SH "RETURN VALUE" .SH 返り値 .\"O The .\"O .BR strftime () .\"O function returns the number of characters placed .\"O in the array \fIs\fP, not including the terminating null byte, .\"O provided the string, including the terminating null byte, fits. .BR strftime () 関数は文字列 \fIs\fP に格納された文字数を返す。 この文字数に終端の NULL バイトは含まない。 終端の NULL バイトを格納できるだけの大きさを持った文字列を渡すこと。 .\"O Otherwise, it returns 0, and the contents of the array is undefined. .\"O (This behavior applies since at least libc 4.4.4; .\"O very old versions of libc, such as libc 4.4.1, .\"O would return \fImax\fP if the array was too small.) それ以外の場合は 0 を返し、文字列の内容は修正されない。 (libc 4.4.4 以降でこの挙動が適用されている。 libc 4.4.1 などの非常に古いバージョンの libc では 文字列が短か過ぎた場合には \fImax\fP が返される。) .LP .\"O Note that the return value 0 does not necessarily indicate an error; .\"O for example, in many locales .\"O .B %p .\"O yields an empty string. 返り値 0 は必ずしもエラーを意味している訳ではないので注意すること。 例えば、多くのロケールでは .B %p は空文字列を返す。 .\"O .SH ENVIRONMENT .SH 環境変数 .\"O The environment variables .\"O .B TZ .\"O and .\"O .B LC_TIME .\"O are used. 環境変数 .B TZ と .B LC_TIME が使用される。 (訳注: .B LC_ALL が設定されている場合には .B LC_TIME よりもそちらが優先される。 .B LC_TIME も .B LC_ALL も設定されていない場合には .B LANG が使用される。) .\"O .SH "CONFORMING TO" .SH 準拠 SVr4, C89, C99. .\"O There are strict inclusions between the set of conversions .\"O given in ANSI C (unmarked), those given in the Single UNIX Specification .\"O (marked SU), those given in Olson's timezone package (marked TZ), .\"O and those given in glibc (marked GNU), except that .\"O .B %+ .\"O is not supported in glibc2. .\"O On the other hand glibc2 has several more extensions. .\"O POSIX.1 only refers to ANSI C; POSIX.2 describes under .\"O .BR date (1) .\"O several extensions that could apply to .\"O .BR strftime () .\"O as well. 個々の変換が厳密にどの規格に含まれるかは、 ANSI C (印なし)、統一 UNIX 規格 (SU印)、Olson の timezone パッケージ (TZ印)、 glibc 独自 (GNU印) で示している。glibc2 では .B %+ はサポートされていないが、 いくつかの拡張が行われている。POSIX.1 では ANSI C のみを参照している。 POSIX.2 の .BR date (1) のところに記述されている幾つかの拡張は .BR strftime () にも適用できるだろう。 .\"O The .\"O .B %F .\"O conversion is in C99 and POSIX.1-2001. .B %F 変換は C99 と POSIX.1-2001 にある。 .\"O In SUSv2, the .\"O .B %S .\"O specifier allowed a range of 00 to 61, .\"O to allow for the theoretical possibility of a minute that .\"O included a double leap second .\"O (there never has been such a minute). SUSv2 では、 .B %S は 00 から 61 の範囲をとると規定されている。 これは、1分間のうち閏秒が 2つ入る可能性が理論的にはあることを 考慮してのものである (実際には、このような状況はこれまで一度も 起こっていない)。 .\"O .SH NOTES .SH 注意 .\"O .SS ISO 8601 Week Dates .SS ISO\ 8601 の週・曜日表記 (Week Dates) .\"O .BR %G , .\"O .BR %g , .\"O and .\"O .BR %V .\"O yield values calculated from the week-based year defined by the .\"O ISO\ 8601 standard. .BR %G , .BR %g , .BR %V は、ISO\ 8601 標準により定義された週単位表記の年により 計算される値を出力する。 .\"O In this system, weeks start on a Monday, and are numbered from 01, .\"O for the first week, up to 52 or 53, for the last week. .\"O Week 1 is the first week where four or more days fall within the .\"O new year (or, synonymously, week 01 is: .\"O the first week of the year that contains a Thursday; .\"O or, the week that has 4 January in it). ISO\ 8601 標準の週単位表記では、週は月曜日から開始され、 週番号は、年の最初の週が 01 となり、最後の週は 52 か 53 となる。 週 01 は、新しい年が 4 日以上含まれる最初の週である。 言い換えると、週 01 は、その年の木曜日を含む最初の週、 つまり 1 月 4 日を含む週ということである。 .\"O When three of fewer days of the first calendar week of the new year fall .\"O within that year, .\"O then the ISO 8601 week-based system counts those days as part of week 53 .\"O of the preceding year. 新しい年のカレンダー上の最初の週に新しい年が 3 日以下しか含まれない場合、 ISO\ 8601 の週単位表記では、これらの日を前の年の週 53 の一部とみなす。 .\"O For example, 1 January 2010 is a Friday, .\"O meaning that just three days of that calendar week fall in 2010. .\"O Thus, the ISO\ 8601 week-based system considers these days to be part of .\"O week 53 (\fB%V\fP) of the year 2009 (\fB%G\fP) ; .\"O week 01 of ISO\ 8601 year 2010 starts on Monday, 4 January 2010. 例えば、2010 年 1 月 1 日は金曜日であり、 その週には 2010 年の日が 3 日しか含まれない。 したがって、ISO\ 8601 の週単位表記では、これらの日は 2009 年 (\fB%G\fP) の週 53 (\fB%V\fP) の一部となる。 ISO\ 8601 の 2010 年の週 01 は 2010 年 1 月 4 日の月曜日から始まる。 .\"O .SS Glibc Notes .SS glibc での注意 .\"O Glibc provides some extensions for conversion specifications. .\"O (These extensions are not specified in POSIX.1-2001, but a few other .\"O systems provide similar features.) .\"O .\" HP-UX and Tru64 also have features like this. .\"O Between the \(aq%\(aq character and the conversion specifier character, .\"O an optional .\"O .I flag .\"O and field .\"O .I width .\"O may be specified. .\"O (These precede the .\"O .B E .\"O or .\"O .B O .\"O modifiers, if present.) glibc では変換指定にいくつか拡張を行っている (これらの拡張は POSIX.1-2001 には規定されていないが、 他のいくつかのシステムで同様の機能が提供されている)。 .\" HP-UX と Tru64 にも同様の機能がある。 \(aq%\(aq 文字と変換指定文字の間に、オプションとして .I flag とフィールドの .I 幅 を指定できる (これらを指定する場合には .B E や .B O 修飾子の前に置く)。 .\"O The following flag characters are permitted: 以下のフラグ文字が使用できる: .TP .B _ .\"O (underscore) .\"O Pad a numeric result string with spaces. (下線) 数値の結果文字列のパディング (穴埋め) をスペース (空白文字) で行う。 .TP .B \- .\"O (dash) .\"O Do not pad a numeric result string. (ダッシュ) 数値の結果文字列に対するパディングを行わない。 .TP .B 0 .\"O Pad a numeric result string with zeros even if the conversion .\"O specifier character uses space-padding by default. 変換指定文字がデフォルトではスペースでパディングを行う場合でも、 数値の結果文字列へのパディングを 0 で行う。 .TP .B ^ .\"O Convert alphabetic characters in result string to upper case. 結果文字列中のアルファベット文字を大文字に変換する。 .TP .B # .\"O Swap the case of the result string. .\"O (This flag only works with certain conversion specifier characters, .\"O and of these, it is only really useful with .\"O .BR %Z .) 結果文字列の大文字・小文字を入れ替える (このフラグは特定の変換指定文字でしか機能しない。その中でも 本当に有用なのは .B %Z の場合だけである)。 .PP .\"O An optional decimal width specifier may follow the (possibly absent) flag. .\"O If the natural size of the field is smaller than this width, .\"O then the result string is padded (on the left) to the specified width. オプションの10進数の幅指定子はフラグの後ろに置くことができる (フラグはなくてもよい)。フィールドの本来の大きさが指定された幅よりも 小さい場合、結果文字列の左側は指定された幅までパディングされる。 .\"O .SH BUGS .SH バグ .\"O Some buggy versions of .\"O .BR gcc (1) .\"O complain about the use of .\"O .BR %c : .\"O .IR "warning: `%c' yields only last 2 digits of year in some locales" . .BR gcc (1) のいくつかのバージョンにはおかしなところがあり、 .B %c の使用法について以下のような警告を出す: .I "warning: `%c' yields only last 2 digits of year in some locales" .RI ( 警告: いくつかのロケールでは `%c' は年の下2桁しか出力しない )。 .\"O Of course programmers are encouraged to use .\"O .BR %c , .\"O it gives the preferred date and time representation. .\"O One meets all kinds of strange obfuscations .\"O to circumvent this .\"O .BR gcc (1) .\"O problem. .\"O A relatively clean one is to add an .\"O intermediate function もちろんプログラマが .B %c を使うのはお薦めできることである。 .B %c を使うと適切な日付と時刻の表記を得ることができるからである。 .BR gcc (1) のこの問題を回避しようとすると、何かすっきりしない気分になるだろう。 比較的きれいな解決方法は以下のような中間関数を追加することである。 .in +4n .nf size_t my_strftime(char *s, size_t max, const char *fmt, const struct tm *tm) { return strftime(s, max, fmt, tm); } .fi .in .RE .\"O Nowadays, .\"O .BR gcc (1) .\"O provides the \fI\-Wno\-format\-y2k\fP option to prevent the warning, .\"O so that the above workaround is no longer required. 現在では、 .BR gcc (1) はこの警告を抑えるための \fI\-Wno\-format\-y2k\fP オプションを 提供しており、上記の回避策はもはや必要ない。 .\"O .SH EXAMPLES .SH 例 .\"O .BR "RFC\ 2822-compliant date format" .\"O (with an English locale for %a and %b) .B "RFC\ 2822 準拠の日付形式" (%a と %b は英語ロケール) .PP .in +2n "%a,\ %d\ %b\ %Y\ %T\ %z" .PP .\"O .BR "RFC\ 822-compliant date format" .\"O (with an English locale for %a and %b) .B "RFC\ 822 準拠の日付形式" (%a と %b は英語ロケール) .PP .in +2n "%a,\ %d\ %b\ %y\ %T\ %z" .\"O .SS Example Program .SS サンプルプログラム .\"O The program below can be used to experiment with .\"O .BR strftime (). 以下のプログラムを使うと .BR strftime () の実験ができる。 .PP .\"O Some examples of the result string produced by the glibc implementation of .\"O .BR strftime () .\"O are as follows: 以下に、 .BR strftime () の glibc 実装が生成する結果の例をいくつか示す: .nf .RB "$" " ./a.out \(aq%m\(aq" Result string is "11" .RB "$" " ./a.out \(aq%5m\(aq" Result string is "00011" .RB "$" " ./a.out \(aq%_5m\(aq" Result string is " 11" .fi .in .PP .\"O Here's the program source: プログラムのソースは以下の通り: .nf #include #include #include int main(int argc, char *argv[]) { char outstr[200]; .PP .\"O Some examples of the result string produced by the glibc implementation of .\"O .BR strftime () .\"O are as follows: 以下に、 .BR strftime () の glibc 実装が生成する結果の例をいくつか示す: .nf $ ./a.out "%m" Result string is "11" $ ./a.out "%5m" Result string is "00011" $ ./a.out "%_5m" Result string is " 11" .fi time_t t; struct tm *tmp; t = time(NULL); tmp = localtime(&t); if (tmp == NULL) { perror("localtime"); exit(EXIT_FAILURE); } if (strftime(outstr, sizeof(outstr), argv[1], tmp) == 0) { fprintf(stderr, "strftime returned 0"); exit(EXIT_FAILURE); } printf("Result string is \\"%s\\"\\n", outstr); exit(EXIT_SUCCESS); } .fi .\"O .SH "SEE ALSO" .SH 関連項目 .BR date (1), .BR time (2), .BR ctime (3), .BR setlocale (3), .BR sprintf (3), .BR strptime (3)