📄 strptime.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"><html><head><!-- Copyright 1997 The Open Group, All Rights Reserved --><title>strptime</title></head><body bgcolor=white><center><font size=2>The Single UNIX ® Specification, Version 2<br>Copyright © 1997 The Open Group</font></center><hr size=2 noshade><h4><a name = "tag_000_009_177"> </a>NAME</h4><blockquote>strptime - date and time conversion</blockquote><h4><a name = "tag_000_009_178"> </a>SYNOPSIS</h4><blockquote><pre><code>#include <<a href="time.h.html">time.h</a>>char *strptime(const char *<i>buf</i>, const char *<i>format</i>, struct tm *<i>tm</i>);</code></pre></blockquote><h4><a name = "tag_000_009_179"> </a>DESCRIPTION</h4><blockquote>The<i>strptime()</i>function converts the character string pointed to by<i>buf</i>to values which are stored in the<b>tm</b>structure pointed to by<i>tm</i>,using the format specified by<i>format</i>.<p>The<i>format</i>is composed of zero or more directives.Each directive is composed of one of the following:one or more white-space characters (as specified by<i><a href="isspace.html">isspace()</a></i>;an ordinary character (neither <i>%</i> nor awhite-space character);or a conversion specification.Each conversion specification is composed of a<i>%</i>character followed by a conversion character whichspecifies the replacement required.There must be white-space or othernon-alphanumeric characters between any twoconversion specifications.The following conversion specifications are supported:<dl compact><dt>%a<dd>is the day of week, using the locale's weekday names;either the abbreviated or full name may be specified.<dt>%A<dd>is the same as %a.<dt>%b<dd>is the month, using the locale's month names;either the abbreviated or full name may be specified.<dt>%B<dd>is the same as %b.<dt>%c<dd>is replaced by the locale's appropriate date and time representation.<dt>%C<dd>is the century number [0,99]; leading zeros are permitted but not required.<dt>%d<dd>is the day of month [1,31]; leading zeros are permitted but not required.<dt>%D<dd>is the date as %m/%d/%y.<dt>%e<dd>is the same as %d.<dt>%h<dd>is the same as %b.<dt>%H<dd>is the hour (24-hour clock) [0,23];leading zeros are permitted but not required.<dt>%I<dd>is the hour (12-hour clock) [1,12];leading zeros are permitted but not required.<dt>%j<dd>is the day number of the year [1,366];leading zeros are permitted but not required.<dt>%m<dd>is the month number [1,12]; leading zeros are permitted but not required.<dt>%M<dd>is the minute [0-59]; leading zeros are permitted but not required.<dt>%n<dd>is any white space.<dt>%p<dd>is the locale's equivalent of a.m or p.m.<dt>%r<dd>12-hour clock time using the AM/PM notation if t_fmt_ampm is not an empty string in the LC_TIME portion of the current locale; in thePOSIX locale, this will be equivalent to %I:%M:%S %p.<dt>%R<dd>is the time as %H:%M.<dt>%S<dd>is the seconds [0,61]; leading zeros are permitted but not required.<dt>%t<dd>is any white space.<dt>%T<dd>is the time as %H:%M:%S.<dt>%U<dd>is the week number of the year (Sunday as the first day ofthe week) as a decimal number [00,53];leading zeros are permitted but not required.<dt>%w<dd>is the weekday as a decimal number [0,6], with 0 representing Sunday;leading zeros are permitted but not required.<dt>%W<dd>is the the week number of the year (Monday as the first day ofthe week) as a decimal number [00,53];leading zeros are permitted but not required.<dt>%x<dd>is the date, using the locale's date format.<dt>%X<dd>is the time, using the locale's time format.<dt>%y<dd>is the year within century.When a century is not otherwise specified,values in the range 69-99 refer to years inthe twentieth century (1969 to 1999 inclusive); values in the range00-68 refer to years in the twenty-first century (2000 to 2068 inclusive).Leading zeros are permitted but not required.<dt>%Y<dd>is the year, including the century (for example, 1988).<dt>%%<dd>is replaced by %.</dl><h5><a name = "tag_000_009_179_001"> </a>Modified Directives</h5>Some directives can be modified by the E and O modifier characters toindicate that an alternative format or specification should be used ratherthan the one normally used by the unmodified directive. If the alternativeformat or specification does not exist in the current locale,the behaviour will be as if the unmodified directive were used.<dl compact><dt>%Ec<dd>is the locale's alternative appropriate date andtime representation.<dt>%EC<dd>is the name of the base year (period) in thelocale's alternative representation.<dt>%Ex<dd>is the locale's alternative date representation.<dt>%EX<dd>is the locale's alternative time representation.<dt>%Ey<dd>is the offset from %EC (year only) in the locale'salternative representation.<dt>%EY<dd>is the full alternative year representation.<dt>%Od<dd>is the day of the month using the locale's alternativenumeric symbols; leading zeros are permitted but not required.<dt>%Oe<dd>is the same as %Od.<dt>%OH<dd>is the hour (24-hour clock) using the locale'salternative numeric symbols.<dt>%OI<dd>is the hour (12-hour clock) using the locale'salternative numeric symbols.<dt>%Om<dd>is the month using the locale's alternative numericsymbols.<dt>%OM<dd>is the minutes using the locale's alternative numericsymbols.<dt>%OS<dd>is the seconds using the locale's alternative numericsymbols.<dt>%OU<dd>is the week number of the year (Sunday as the firstday of the week) using the locale's alternative numeric symbols.<dt>%Ow<dd>is the number of the weekday (Sunday=0) usingthe locale's alternative numeric symbols.<dt>%OW<dd>is the week number of the year (Monday as the firstday of the week) using the locale's alternative numeric symbols.<dt>%Oy<dd>is the year (offset from %C) using the locale's alternativenumeric symbols.</dl><p>A directive composed of white-space characters isexecuted by scanning inputup to the first character that is not white-space(which remains unscanned),or until no more characters can be scanned.<p>A directive that is an ordinary character is executedby scanning the next character from the buffer.If the character scanned from the buffer differs from the onecomprising thedirective, the directive fails, and the differing and subsequentcharacters remain unscanned.<p>A series of directives composed of %n, %t, white-space characters or anycombination is executed by scanningup to the first character that is not white space (which remains unscanned),or until no more characters can be scanned.<p>Any other conversion specification is executed by scanning characters until acharacter matching the next directive is scanned, or until no more characterscan be scanned. These characters, except the one matching the nextdirective, are then compared to the locale values associated with theconversion specifier. If a match is found, values for the appropriate<b>tm</b>structure members are set to values corresponding to the locale information.Case is ignored when matching items in<i>buf</i>such as month or weekday names.If no match is found,<i>strptime()</i>fails and no more characters are scanned.<br></blockquote><h4><a name = "tag_000_009_180"> </a>RETURN VALUE</h4><blockquote>Upon successful completion,<i>strptime()</i>returns a pointer to the character following the last character parsed.Otherwise, a null pointer is returned.</blockquote><h4><a name = "tag_000_009_181"> </a>ERRORS</h4><blockquote>No errors are defined.</blockquote><h4><a name = "tag_000_009_182"> </a>EXAMPLES</h4><blockquote>None.</blockquote><h4><a name = "tag_000_009_183"> </a>APPLICATION USAGE</h4><blockquote>Several "same as" formats, and the special processingof white-space characters are provided in order to ease the useof identical<i>format</i>strings for<i><a href="strftime.html">strftime()</a></i>and<i>strptime()</i>.<p>Applications should use %Y (4-digit years) in preference to %y(2-digit years).<p>It is unspecified whether multiple calls to <i>strptime()</i> using the same <b>tm</b>structure will update the current contents of the structureor overwrite all contents of the structure. Portable applicationsshould make a single call to <i>strptime()</i>with a format and all dataneeded to completely specify the date and time being converted.</blockquote><h4><a name = "tag_000_009_184"> </a>FUTURE DIRECTIONS</h4><blockquote>This function is expected to be mandatory in the next issue of thisspecification.</blockquote><h4><a name = "tag_000_009_185"> </a>SEE ALSO</h4><blockquote><i><a href="scanf.html">scanf()</a></i>,<i><a href="strftime.html">strftime()</a></i>,<i><a href="time.html">time()</a></i>,<i><a href="time.h.html"><time.h></a></i>.</blockquote><hr size=2 noshade><center><font size=2>UNIX ® is a registered Trademark of The Open Group.<br>Copyright © 1997 The Open Group<br> [ <a href="../index.html">Main Index</a> | <a href="../xshix.html">XSH</a> | <a href="../xcuix.html">XCU</a> | <a href="../xbdix.html">XBD</a> | <a href="../cursesix.html">XCURSES</a> | <a href="../xnsix.html">XNS</a> ]</font></center><hr size=2 noshade></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -