]> CyberLeo.Net >> Repos - FreeBSD/releng/10.0.git/blob - lib/libc/stdtime/strptime.3
- Copy stable/10 (r259064) to releng/10.0 as part of the
[FreeBSD/releng/10.0.git] / lib / libc / stdtime / strptime.3
1 .\"
2 .\" Copyright (c) 1997 Joerg Wunsch
3 .\"
4 .\" All rights reserved.
5 .\"
6 .\" Redistribution and use in source and binary forms, with or without
7 .\" modification, are permitted provided that the following conditions
8 .\" are met:
9 .\" 1. Redistributions of source code must retain the above copyright
10 .\"    notice, this list of conditions and the following disclaimer.
11 .\" 2. Redistributions in binary form must reproduce the above copyright
12 .\"    notice, this list of conditions and the following disclaimer in the
13 .\"    documentation and/or other materials provided with the distribution.
14 .\"
15 .\" THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY EXPRESS OR
16 .\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 .\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 .\" IN NO EVENT SHALL THE DEVELOPERS BE LIABLE FOR ANY DIRECT, INDIRECT,
19 .\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 .\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 .\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 .\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 .\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 .\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 .\"
26 .\" $FreeBSD$
27 .\" "
28 .Dd June 25, 2012
29 .Dt STRPTIME 3
30 .Os
31 .Sh NAME
32 .Nm strptime
33 .Nd parse date and time string
34 .Sh LIBRARY
35 .Lb libc
36 .Sh SYNOPSIS
37 .In time.h
38 .Ft char *
39 .Fo strptime
40 .Fa "const char * restrict buf"
41 .Fa "const char * restrict format"
42 .Fa "struct tm * restrict timeptr"
43 .Fc
44 .In time.h
45 .In xlocale.h
46 .Ft char *
47 .Fn strptime_l "const char * restrict buf" "const char * restrict format" "struct tm * restrict timeptr" "locale_t loc"
48 .Sh DESCRIPTION
49 The
50 .Fn strptime
51 function parses the string in the buffer
52 .Fa buf
53 according to the string pointed to by
54 .Fa format ,
55 and fills in the elements of the structure pointed to by
56 .Fa timeptr .
57 The resulting values will be relative to the local time zone.
58 Thus, it can be considered the reverse operation of
59 .Xr strftime 3 .
60 The
61 .Fn strptime_l
62 function does the same as
63 .Fn strptime ,
64 but takes an explicit locale rather than using the current locale.
65 .Pp
66 The
67 .Fa format
68 string consists of zero or more conversion specifications and
69 ordinary characters.
70 All ordinary characters are matched exactly with the buffer, where
71 white space in the format string will match any amount of white space
72 in the buffer.
73 All conversion specifications are identical to those described in
74 .Xr strftime 3 .
75 .Pp
76 Two-digit year values, including formats
77 .Fa %y
78 and
79 .Fa \&%D ,
80 are now interpreted as beginning at 1969 per POSIX requirements.
81 Years 69-00 are interpreted in the 20th century (1969-2000), years
82 01-68 in the 21st century (2001-2068).
83 .Pp
84 If the
85 .Fa format
86 string does not contain enough conversion specifications to completely
87 specify the resulting
88 .Vt struct tm ,
89 the unspecified members of
90 .Va timeptr
91 are left untouched.
92 For example, if
93 .Fa format
94 is
95 .Dq Li "%H:%M:%S" ,
96 only
97 .Va tm_hour ,
98 .Va tm_sec
99 and
100 .Va tm_min
101 will be modified.
102 If time relative to today is desired, initialize the
103 .Fa timeptr
104 structure with today's date before passing it to
105 .Fn strptime .
106 .Sh RETURN VALUES
107 Upon successful completion,
108 .Fn strptime
109 returns the pointer to the first character in
110 .Fa buf
111 that has not been required to satisfy the specified conversions in
112 .Fa format .
113 It returns
114 .Dv NULL
115 if one of the conversions failed.
116 .Fn strptime_l
117 returns the same values as
118 .Fn strptime .
119 .Sh SEE ALSO
120 .Xr date 1 ,
121 .Xr scanf 3 ,
122 .Xr strftime 3
123 .Sh HISTORY
124 The
125 .Fn strptime
126 function appeared in
127 .Fx 3.0 .
128 .Sh AUTHORS
129 The
130 .Fn strptime
131 function has been contributed by Powerdog Industries.
132 .Pp
133 This man page was written by
134 .An J\(:org Wunsch .
135 .Sh BUGS
136 Both the
137 .Fa %e
138 and
139 .Fa %l
140 format specifiers may incorrectly scan one too many digits
141 if the intended values comprise only a single digit
142 and that digit is followed immediately by another digit.
143 Both specifiers accept zero-padded values,
144 even though they are both defined as taking unpadded values.
145 .Pp
146 The
147 .Fa %p
148 format specifier has no effect unless it is parsed
149 .Em after
150 hour-related specifiers.
151 Specifying
152 .Fa %l
153 without
154 .Fa %p
155 will produce undefined results.
156 Note that 12AM
157 (ante meridiem)
158 is taken as midnight
159 and 12PM
160 (post meridiem)
161 is taken as noon.
162 .Pp
163 The
164 .Fa \&%U
165 and
166 .Fa %W
167 format specifiers accept any value within the range 00 to 53
168 without validating against other values supplied (like month
169 or day of the year, for example).
170 .Pp
171 The
172 .Fa %Z
173 format specifier only accepts time zone abbreviations of the local time zone,
174 or the value "GMT".
175 This limitation is because of ambiguity due to of the over loading of time
176 zone abbreviations.
177 One such example is
178 .Fa EST
179 which is both Eastern Standard Time and Eastern Australia Summer Time.
180 .Pp
181 The
182 .Fn strptime
183 function does not correctly handle multibyte characters in the
184 .Fa format
185 argument.