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