1 '\" te
   2 .\" Copyright (c) 1992, X/Open Company Limited.  All Rights Reserved.
   3 .\" Portions Copyright (c) 2007, Sun Microsystems, Inc. All Rights Reserved.
   4 .\" Sun Microsystems, Inc. gratefully acknowledges The Open Group for permission to reproduce portions of its copyrighted documentation. Original documentation from The Open Group can be obtained online at
   5 .\" http://www.opengroup.org/bookstore/.
   6 .\" The Institute of Electrical and Electronics Engineers and The Open Group, have given us permission to reprint portions of their documentation. In the following statement, the phrase "this text" refers to portions of the system documentation. Portions of this text are reprinted and reproduced in electronic form in the Sun OS Reference Manual, from IEEE Std 1003.1, 2004 Edition, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 6, Copyright (C) 2001-2004 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between these versions and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained online at http://www.opengroup.org/unix/online.html.
   7 .\"  This notice shall appear on any product containing this material.
   8 .\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License").  You may not use this file except in compliance with the License.
   9 .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing.  See the License for the specific language governing permissions and limitations under the License.
  10 .\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE.  If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
  11 .TH STRPTIME 3C "Aug 27, 2007"
  12 .SH NAME
  13 strptime \- date and time conversion
  14 .SH SYNOPSIS
  15 .LP
  16 .nf
  17 #include <time.h>
  18 
  19 \fBchar *\fR\fBstrptime\fR(\fBconst char *restrict\fR \fIbuf\fR,
  20      \fBconst char *restrict\fR \fIformat\fR, \fBstruct tm *restrict\fR \fItm\fR);
  21 .fi
  22 
  23 .SS "Non-zeroing Behavior"
  24 .LP
  25 .nf
  26 \fBcc\fR [\fIflag\fR...]  \fIfile\fR... \fB-D_STRPTIME_DONTZERO\fR [\fIlibrary\fR...]
  27 #include <time.h>
  28 
  29 \fBchar *\fR\fBstrptime\fR(\fBconst char *restrict\fR \fIbuf\fR,
  30      \fBconst char *restrict\fR \fIformat\fR, \fBstruct tm *restrict\fR \fItm\fR);
  31 .fi
  32 
  33 .SH DESCRIPTION
  34 .sp
  35 .LP
  36 The \fBstrptime()\fR function converts the character string pointed to by
  37 \fIbuf\fR to values which are stored in the \fBtm\fR structure pointed to by
  38 \fItm\fR, using the format specified by \fIformat\fR.
  39 .sp
  40 .LP
  41 The \fIformat\fR argument is composed of zero or more conversion
  42 specifications. Each conversion specification is composed of a "%" (percent)
  43 character followed by one or two conversion characters which specify the
  44 replacement required. One or more white space characters (as specified by
  45 \fBisspace\fR(3C)) may precede or follow a conversion specification. There must
  46 be white-space or other non-alphanumeric characters between any two conversion
  47 specifications.
  48 .sp
  49 .LP
  50 A non-zeroing version of \fBstrptime()\fR, described below under \fBNon-zeroing
  51 Behavior\fR, is provided if \fB_STRPTIME_DONTZERO\fR is defined.
  52 .SS "Conversion Specifications"
  53 .sp
  54 .LP
  55 The following conversion specifications are supported:
  56 .sp
  57 .ne 2
  58 .na
  59 \fB\fB%%\fR\fR
  60 .ad
  61 .RS 6n
  62 Same as \fB%\fR.
  63 .RE
  64 
  65 .sp
  66 .ne 2
  67 .na
  68 \fB\fB%a\fR\fR
  69 .ad
  70 .RS 6n
  71 Day of week, using the locale's weekday names;  either the abbreviated or full
  72 name may be specified.
  73 .RE
  74 
  75 .sp
  76 .ne 2
  77 .na
  78 \fB\fB%A\fR\fR
  79 .ad
  80 .RS 6n
  81 Same as \fB%a\fR.
  82 .RE
  83 
  84 .sp
  85 .ne 2
  86 .na
  87 \fB\fB%b\fR\fR
  88 .ad
  89 .RS 6n
  90 Month, using the locale's month names;  either the abbreviated or full name may
  91 be specified.
  92 .RE
  93 
  94 .sp
  95 .ne 2
  96 .na
  97 \fB\fB%B\fR\fR
  98 .ad
  99 .RS 6n
 100 Same as \fB%b\fR.
 101 .RE
 102 
 103 .sp
 104 .ne 2
 105 .na
 106 \fB\fB%c\fR\fR
 107 .ad
 108 .RS 6n
 109 Locale's appropriate date and time representation.
 110 .RE
 111 
 112 .sp
 113 .ne 2
 114 .na
 115 \fB\fB%C\fR\fR
 116 .ad
 117 .RS 6n
 118 Century number (the year divided by 100 and truncated to an integer as a
 119 decimal number [1,99]); single digits are preceded by 0. If \fB%C\fR is used
 120 without the \fB%y\fR specifier, \fBstrptime()\fR assumes the year offset is
 121 zero in whichever century is specified.   Note the behavior of \fB%C\fR in the
 122 absence of \fB%y\fR is not specified by any of the standards or specifications
 123 described on the \fBstandards\fR(5) manual page, so portable applications
 124 should not depend on it.  This behavior may change in a future release.
 125 .RE
 126 
 127 .sp
 128 .ne 2
 129 .na
 130 \fB\fB%d\fR\fR
 131 .ad
 132 .RS 6n
 133 Day of month [1,31]; leading zero is permitted but not required.
 134 .RE
 135 
 136 .sp
 137 .ne 2
 138 .na
 139 \fB\fB%D\fR\fR
 140 .ad
 141 .RS 6n
 142 Date as \fB%m\fR/\fB%d\fR/\fB%y\fR.
 143 .RE
 144 
 145 .sp
 146 .ne 2
 147 .na
 148 \fB\fB%e\fR\fR
 149 .ad
 150 .RS 6n
 151 Same as \fB%d\fR.
 152 .RE
 153 
 154 .sp
 155 .ne 2
 156 .na
 157 \fB\fB%h\fR\fR
 158 .ad
 159 .RS 6n
 160 Same as \fB%b\fR.
 161 .RE
 162 
 163 .sp
 164 .ne 2
 165 .na
 166 \fB\fB%H\fR\fR
 167 .ad
 168 .RS 6n
 169 Hour (24-hour clock) [0,23];  leading zero is permitted but not required.
 170 .RE
 171 
 172 .sp
 173 .ne 2
 174 .na
 175 \fB\fB%I\fR\fR
 176 .ad
 177 .RS 6n
 178 Hour (12-hour clock) [1,12];  leading zero is permitted but not required.
 179 .RE
 180 
 181 .sp
 182 .ne 2
 183 .na
 184 \fB\fB%j\fR\fR
 185 .ad
 186 .RS 6n
 187 Day number of the year [1,366];  leading zeros are permitted but not required.
 188 .RE
 189 
 190 .sp
 191 .ne 2
 192 .na
 193 \fB\fB%m\fR\fR
 194 .ad
 195 .RS 6n
 196 Month number [1,12]; leading zero is permitted but not required.
 197 .RE
 198 
 199 .sp
 200 .ne 2
 201 .na
 202 \fB\fB%M\fR\fR
 203 .ad
 204 .RS 6n
 205 Minute [0-59]; leading zero is permitted but not required.
 206 .RE
 207 
 208 .sp
 209 .ne 2
 210 .na
 211 \fB\fB%n\fR\fR
 212 .ad
 213 .RS 6n
 214 Any white space.
 215 .RE
 216 
 217 .sp
 218 .ne 2
 219 .na
 220 \fB\fB%p\fR\fR
 221 .ad
 222 .RS 6n
 223 Locale's equivalent of either a.m. or p.m.
 224 .RE
 225 
 226 .sp
 227 .ne 2
 228 .na
 229 \fB\fB%r\fR\fR
 230 .ad
 231 .RS 6n
 232 Appropriate time representation in the 12-hour clock format with \fB%p\fR.
 233 .RE
 234 
 235 .sp
 236 .ne 2
 237 .na
 238 \fB\fB%R\fR\fR
 239 .ad
 240 .RS 6n
 241 Time as \fB%H\fR:\fB%M\fR.
 242 .RE
 243 
 244 .SS "SUSv3"
 245 .sp
 246 .ne 2
 247 .na
 248 \fB\fB%S\fR\fR
 249 .ad
 250 .RS 6n
 251 Seconds [0,60]; leading zero is permitted but not required. The range of values
 252 is [00,60] rather than [00,59] to allow for the occasional leap second.
 253 .RE
 254 
 255 .SS "Default and other standards"
 256 .sp
 257 .ne 2
 258 .na
 259 \fB\fB%S\fR\fR
 260 .ad
 261 .RS 6n
 262 Seconds [0,61]; leading zero is permitted but not required. The range of values
 263 is [00,61] rather than [00,59] to allow for the occasional leap second and even
 264 more occasional double leap second.
 265 .RE
 266 
 267 .sp
 268 .ne 2
 269 .na
 270 \fB\fB%t\fR\fR
 271 .ad
 272 .RS 6n
 273 Any white space.
 274 .RE
 275 
 276 .sp
 277 .ne 2
 278 .na
 279 \fB\fB%T\fR\fR
 280 .ad
 281 .RS 6n
 282 Time as \fB%H\fR:\fB%M\fR:\fB%S\fR.
 283 .RE
 284 
 285 .sp
 286 .ne 2
 287 .na
 288 \fB\fB%U\fR\fR
 289 .ad
 290 .RS 6n
 291 Week number of the year as a decimal number [0,53], with Sunday as the first
 292 day of the week; leading zero is permitted but not required.
 293 .RE
 294 
 295 .sp
 296 .ne 2
 297 .na
 298 \fB\fB%w\fR\fR
 299 .ad
 300 .RS 6n
 301 Weekday as a decimal number [0,6], with 0 representing Sunday.
 302 .RE
 303 
 304 .sp
 305 .ne 2
 306 .na
 307 \fB\fB%W\fR\fR
 308 .ad
 309 .RS 6n
 310 Week number of the year as a decimal number [0,53], with Monday as the first
 311 day of the week; leading zero is permitted but not required.
 312 .RE
 313 
 314 .sp
 315 .ne 2
 316 .na
 317 \fB\fB%x\fR\fR
 318 .ad
 319 .RS 6n
 320 Locale's appropriate date representation.
 321 .RE
 322 
 323 .sp
 324 .ne 2
 325 .na
 326 \fB\fB%X\fR\fR
 327 .ad
 328 .RS 6n
 329 Locale's appropriate time representation.
 330 .RE
 331 
 332 .sp
 333 .ne 2
 334 .na
 335 \fB\fB%y\fR\fR
 336 .ad
 337 .RS 6n
 338 Year within century. When a century is not otherwise specified, values in the
 339 range 69-99 refer to years in the twentieth century (1969 to 1999 inclusive);
 340 values in the range 00-68 refer to years in the twenty-first century (2000 to
 341 2068 inclusive).
 342 .RE
 343 
 344 .sp
 345 .ne 2
 346 .na
 347 \fB\fB%Y\fR\fR
 348 .ad
 349 .RS 6n
 350 Year, including the century (for example, 1993).
 351 .RE
 352 
 353 .sp
 354 .ne 2
 355 .na
 356 \fB\fB%Z\fR\fR
 357 .ad
 358 .RS 6n
 359 Time zone name or no characters if no time zone exists.
 360 .RE
 361 
 362 .SS "Modified Conversion Specifications"
 363 .sp
 364 .LP
 365 Some conversion specifications can be modified by the \fBE\fR and \fBO\fR
 366 modifier characters to indicate that an alternate format or specification
 367 should be used rather than the one normally used by the unmodified
 368 specification. If the alternate format or specification does not exist in the
 369 current locale, the behavior will be as if the unmodified conversion
 370 specification were used.
 371 .sp
 372 .ne 2
 373 .na
 374 \fB\fB%Ec\fR\fR
 375 .ad
 376 .RS 7n
 377 Locale's alternate appropriate date and time representation.
 378 .RE
 379 
 380 .sp
 381 .ne 2
 382 .na
 383 \fB\fB%EC\fR\fR
 384 .ad
 385 .RS 7n
 386 Name of the base year (era) in the locale's alternate representation.
 387 .RE
 388 
 389 .sp
 390 .ne 2
 391 .na
 392 \fB\fB%Ex\fR\fR
 393 .ad
 394 .RS 7n
 395 Locale's alternate date representation.
 396 .RE
 397 
 398 .sp
 399 .ne 2
 400 .na
 401 \fB\fB%EX\fR\fR
 402 .ad
 403 .RS 7n
 404 Locale's alternate time representation.
 405 .RE
 406 
 407 .sp
 408 .ne 2
 409 .na
 410 \fB\fB%Ey\fR\fR
 411 .ad
 412 .RS 7n
 413 Offset from \fB%EC\fR (year only) in the locale's alternate representation.
 414 .RE
 415 
 416 .sp
 417 .ne 2
 418 .na
 419 \fB\fB%EY\fR\fR
 420 .ad
 421 .RS 7n
 422 Full alternate year representation.
 423 .RE
 424 
 425 .sp
 426 .ne 2
 427 .na
 428 \fB\fB%Od\fR\fR
 429 .ad
 430 .RS 7n
 431 Day of the month using the locale's alternate numeric symbols.
 432 .RE
 433 
 434 .sp
 435 .ne 2
 436 .na
 437 \fB\fB%Oe\fR\fR
 438 .ad
 439 .RS 7n
 440 Same as \fB%Od\fR.
 441 .RE
 442 
 443 .sp
 444 .ne 2
 445 .na
 446 \fB\fB%OH\fR\fR
 447 .ad
 448 .RS 7n
 449 Hour (24-hour clock) using the locale's alternate numeric symbols.
 450 .RE
 451 
 452 .sp
 453 .ne 2
 454 .na
 455 \fB\fB%OI\fR\fR
 456 .ad
 457 .RS 7n
 458 Hour (12-hour clock) using the locale's alternate numeric symbols.
 459 .RE
 460 
 461 .sp
 462 .ne 2
 463 .na
 464 \fB\fB%Om\fR\fR
 465 .ad
 466 .RS 7n
 467 Month using the locale's alternate numeric symbols.
 468 .RE
 469 
 470 .sp
 471 .ne 2
 472 .na
 473 \fB\fB%OM\fR\fR
 474 .ad
 475 .RS 7n
 476 Minutes using the locale's alternate numeric symbols.
 477 .RE
 478 
 479 .sp
 480 .ne 2
 481 .na
 482 \fB\fB%OS\fR\fR
 483 .ad
 484 .RS 7n
 485 Seconds using the locale's alternate numeric symbols.
 486 .RE
 487 
 488 .sp
 489 .ne 2
 490 .na
 491 \fB\fB%OU\fR\fR
 492 .ad
 493 .RS 7n
 494 Week number of the year (Sunday as the first day of the week) using the
 495 locale's alternate numeric symbols.
 496 .RE
 497 
 498 .sp
 499 .ne 2
 500 .na
 501 \fB\fB%Ow\fR\fR
 502 .ad
 503 .RS 7n
 504 Number of the weekday (Sunday=0) using the  locale's alternate numeric symbols.
 505 .RE
 506 
 507 .sp
 508 .ne 2
 509 .na
 510 \fB\fB%OW\fR\fR
 511 .ad
 512 .RS 7n
 513 Week number of the year (Monday as the first day of the week) using the
 514 locale's alternate numeric symbols.
 515 .RE
 516 
 517 .sp
 518 .ne 2
 519 .na
 520 \fB\fB%Oy\fR\fR
 521 .ad
 522 .RS 7n
 523 Year (offset from \fB%C\fR) in the locale's alternate  representation and using
 524 the locale's alternate numeric symbols.
 525 .RE
 526 
 527 .SS "General Specifications"
 528 .sp
 529 .LP
 530 A conversion specification that is an ordinary character is executed by
 531 scanning the next character from the buffer. If the character scanned from the
 532 buffer differs from the one comprising the specification, the specification
 533 fails, and the differing and subsequent characters remain unscanned.
 534 .sp
 535 .LP
 536 A series of specifications composed of \fB%n\fR, \fB%t\fR, white-space
 537 characters or any combination is executed by scanning up to the first character
 538 that is not white space (which remains unscanned), or until no more characters
 539 can be scanned.  White space is defined by \fBisspace\fR(3C).
 540 .sp
 541 .LP
 542 Any other conversion specification is executed by scanning characters until a
 543 character matching the next specification is scanned, or until no more
 544 characters can be scanned. These characters, except the one matching the next
 545 specification, are then compared to the locale values associated with the
 546 conversion specifier.  If a match is found, values for the appropriate
 547 \fItm\fR structure members are set to values corresponding to the locale
 548 information. If no match is found,  \fBstrptime()\fR fails and no more
 549 characters are scanned.
 550 .sp
 551 .LP
 552 The month names, weekday names, era names, and alternate numeric symbols can
 553 consist of any combination of upper and lower case letters.  The user can
 554 request that the input date or time specification be in a specific language by
 555 setting the \fBLC_TIME\fR category using \fBsetlocale\fR(3C).
 556 .SS "Non-zeroing Behavior"
 557 .sp
 558 .LP
 559 In addition to the behavior described above by various standards, the Solaris
 560 implementation of \fBstrptime()\fR provides the following extensions. These may
 561 change at any time in the future.  Portable applications should not depend on
 562 these extended features:
 563 .RS +4
 564 .TP
 565 .ie t \(bu
 566 .el o
 567 If \fB_STRPTIME_DONTZERO\fR is not defined, the \fBtm struct\fR is zeroed on
 568 entry and \fBstrptime()\fR updates the fields of the \fBtm struct\fR associated
 569 with the specifiers in the format string.
 570 .RE
 571 .RS +4
 572 .TP
 573 .ie t \(bu
 574 .el o
 575 If \fB_STRPTIME_DONTZERO\fR is defined, \fBstrptime()\fR does not zero the
 576 \fBtm struct\fR on entry.  Additionally, for some specifiers, \fBstrptime()\fR
 577 will use some values in the input \fBtm struct\fR to recalculate the date and
 578 re-assign the appropriate members of the \fBtm struct\fR.
 579 .RE
 580 .sp
 581 .LP
 582 The following describes extended features regardless of whether
 583 \fB_STRPTIME_DONTZERO\fR is defined or not defined:
 584 .RS +4
 585 .TP
 586 .ie t \(bu
 587 .el o
 588 If \fB%j\fR is specified, \fBtm_yday\fR is set;  if year is given, and if month
 589 and day are not given, \fBstrptime()\fR calculates and sets \fBtm_mon\fR,
 590 \fBtm_mday\fR, and \fBtm_year\fR.
 591 .RE
 592 .RS +4
 593 .TP
 594 .ie t \(bu
 595 .el o
 596 If \fB%U\fR or \fB%W\fR is specified and if weekday and year are given and
 597 month and day of month are not given, \fBstrptime()\fR calculates and sets
 598 \fBtm_mon\fR, \fBtm_mday\fR, \fBtm_wday\fR, and \fBtm_year\fR.
 599 .RE
 600 .sp
 601 .LP
 602 The following describes extended features when \fB_STRPTIME_DONTZERO\fR is not
 603 defined:
 604 .RS +4
 605 .TP
 606 .ie t \(bu
 607 .el o
 608 If \fB%C\fR is specified and \fB%y\fR is not specified, \fBstrptime()\fRassumes
 609 0 as the year offset, then calculates the year, and assigns \fBtm_year\fR.
 610 .RE
 611 .sp
 612 .LP
 613 The following describes extended features when \fB_STRPTIME_DONTZERO\fR is
 614 defined:
 615 .RS +4
 616 .TP
 617 .ie t \(bu
 618 .el o
 619 If \fB%C\fR is specified and \fB%y\fR is not specified, \fBstrptime()\fR
 620 assumes the year offset of the year value of the \fBtm_year\fR member of the
 621 input \fBtm struct\fR, then calculates the year and assigns \fBtm_year\fR.
 622 .RE
 623 .RS +4
 624 .TP
 625 .ie t \(bu
 626 .el o
 627 If \fB%j\fR is specified and neither \fB%y\fR, \fB%Y\fR, nor \fB%C\fR are
 628 specified, and neither month nor day of month are specified, \fBstrptime()\fR
 629 assumes the year value given by the value of the \fBtm_year\fR field of the
 630 input \fBtm struct\fR.  Then, in addition to setting \fBtm_yday\fR,
 631 \fBstrptime()\fR uses day-of-year and year values to calculate the month and
 632 day-of-month, and assigns \fBtm_month\fR and \fBtm_mday\fR.
 633 .RE
 634 .RS +4
 635 .TP
 636 .ie t \(bu
 637 .el o
 638 If \fB%U\fR or \fB%W\fR is specified, and if weekday and/or year are not given,
 639 and month and day of month are not given, \fBstrptime()\fR will assume the
 640 weekday value and/or the year value as the value of the \fBtm_wday\fR field
 641 and/or \fBtm_year\fR field of the input \fBtm struct\fR.  Then,
 642 \fBstrptime()\fR will calculate the month and day-of-month and assign
 643 \fBtm_month\fR, \fBtm_mday\fR, and/or \fBtm_year\fR.
 644 .RE
 645 .RS +4
 646 .TP
 647 .ie t \(bu
 648 .el o
 649 If \fB%p\fR is specified and if hour is not specified, \fBstrptime()\fR will
 650 reference, and if needed, update the \fBtm_hour\fR member. If the \fBam_pm\fR
 651 input is p.m. and the input \fBtm_hour\fR value is between 0 - 11,
 652 \fBstrptime()\fR will add 12 hours and update \fBtm_hour\fR.  If the
 653 \fBam_pm\fR input is a.m. and input \fBtm_hour\fR value is between 12 - 23,
 654 \fBstrptime()\fR will subtract 12 hours and update \fBtm_hour\fR.
 655 .RE
 656 .SH RETURN VALUES
 657 .sp
 658 .LP
 659 Upon successful completion, \fBstrptime()\fR returns a pointer to the character
 660 following the last character parsed. Otherwise, a null pointer is returned.
 661 .SH USAGE
 662 .sp
 663 .LP
 664 Several "same as" formats, and the special processing of white-space characters
 665 are provided in order to ease the use of identical  \fIformat\fR strings for
 666 \fBstrftime\fR(3C) and \fBstrptime()\fR.
 667 .sp
 668 .LP
 669 The \fBstrptime()\fR function tries to calculate \fBtm_year\fR, \fBtm_mon\fR,
 670 and \fBtm_mday\fR when given incomplete input.  This allows the \fBstruct tm\fR
 671 created by \fBstrptime()\fR to be passed to \fBmktime\fR(3C) to produce a
 672 \fBtime_t\fR value for dates and times that are representable by a
 673 \fBtime_t\fR.  As an example, since \fBmktime()\fR ignores \fBtm_yday\fR,
 674 \fBstrptime()\fR calculates \fBtm_mon\fR and \fBtm_mday\fR as well as filling
 675 in \fBtm_yday\fR when \fB%j\fR is specified without otherwise specifying a
 676 month and day within month.
 677 .SH ATTRIBUTES
 678 .sp
 679 .LP
 680 See \fBattributes\fR(5) for descriptions of the following attributes:
 681 .sp
 682 
 683 .sp
 684 .TS
 685 box;
 686 c | c
 687 l | l .
 688 ATTRIBUTE TYPE  ATTRIBUTE VALUE
 689 _
 690 CSI     Enabled
 691 _
 692 Interface Stability     Committed
 693 _
 694 MT-Level        MT-Safe
 695 _
 696 Standard        See \fBstandards\fR(5).
 697 .TE
 698 
 699 .SH SEE ALSO
 700 .sp
 701 .LP
 702 \fBctime\fR(3C), \fBgetdate\fR(3C), \fBisspace\fR(3C), \fBmktime\fR(3C),
 703 \fBsetlocale\fR(3C), \fBstrftime\fR(3C), \fBattributes\fR(5), \fBenviron\fR(5),
 704 \fBstandards\fR(5)