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 "Jun 27, 2014" 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 .fi 22 .LP 23 .nf 24 #include <time.h> 25 #include <xlocale.h> 26 27 \fBchar *\fR\fBstrptime_l\fR(\fBconst char *restrict\fR \fIbuf\fR, 28 \fBconst char *restrict\fR \fIformat\fR, \fBstruct tm *restrict\fR \fItm\fR, 29 \fBlocale_t\fR \fIloc\fR); 30 .fi 31 .SS "Non-zeroing Behavior" 32 .LP 33 .nf 34 \fBcc\fR [\fIflag\fR...] \fIfile\fR... \fB-D_STRPTIME_DONTZERO\fR [\fIlibrary\fR...] 35 #include <time.h> 36 37 \fBchar *\fR\fBstrptime\fR(\fBconst char *restrict\fR \fIbuf\fR, 38 \fBconst char *restrict\fR \fIformat\fR, \fBstruct tm *restrict\fR \fItm\fR); 39 .fi 40 41 .SH DESCRIPTION 42 .LP 43 The \fBstrptime()\fR function converts the character string pointed to by 44 \fIbuf\fR to values which are stored in the \fBtm\fR structure pointed to by 45 \fItm\fR, using the format specified by \fIformat\fR. The \fBstrptime_l()\fR 46 function is identical to \fBstrptime()\fR except instead of acting in the 47 current locale, it acts in the locale specified by the argument \fIloc\fR. 48 .LP 49 The \fIformat\fR argument is composed of zero or more conversion 50 specifications. Each conversion specification is composed of a "%" (percent) 51 character followed by one or two conversion characters which specify the 52 replacement required. One or more white space characters (as specified by 53 \fBisspace\fR(3C)) may precede or follow a conversion specification. There must 54 be white-space or other non-alphanumeric characters between any two conversion 55 specifications. 56 .LP 57 A non-zeroing version of \fBstrptime()\fR, described below under \fBNon-zeroing 58 Behavior\fR, is provided if \fB_STRPTIME_DONTZERO\fR is defined. 59 .SS "Conversion Specifications" 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 .LP 370 Some conversion specifications can be modified by the \fBE\fR and \fBO\fR 371 modifier characters to indicate that an alternate format or specification 372 should be used rather than the one normally used by the unmodified 373 specification. If the alternate format or specification does not exist in the 374 current locale, the behavior will be as if the unmodified conversion 375 specification were used. 376 .sp 377 .ne 2 378 .na 379 \fB\fB%Ec\fR\fR 380 .ad 381 .RS 7n 382 Locale's alternate appropriate date and time representation. 383 .RE 384 385 .sp 386 .ne 2 387 .na 388 \fB\fB%EC\fR\fR 389 .ad 390 .RS 7n 391 Name of the base year (era) in the locale's alternate representation. 392 .RE 393 394 .sp 395 .ne 2 396 .na 397 \fB\fB%Ex\fR\fR 398 .ad 399 .RS 7n 400 Locale's alternate date representation. 401 .RE 402 403 .sp 404 .ne 2 405 .na 406 \fB\fB%EX\fR\fR 407 .ad 408 .RS 7n 409 Locale's alternate time representation. 410 .RE 411 412 .sp 413 .ne 2 414 .na 415 \fB\fB%Ey\fR\fR 416 .ad 417 .RS 7n 418 Offset from \fB%EC\fR (year only) in the locale's alternate representation. 419 .RE 420 421 .sp 422 .ne 2 423 .na 424 \fB\fB%EY\fR\fR 425 .ad 426 .RS 7n 427 Full alternate year representation. 428 .RE 429 430 .sp 431 .ne 2 432 .na 433 \fB\fB%Od\fR\fR 434 .ad 435 .RS 7n 436 Day of the month using the locale's alternate numeric symbols. 437 .RE 438 439 .sp 440 .ne 2 441 .na 442 \fB\fB%Oe\fR\fR 443 .ad 444 .RS 7n 445 Same as \fB%Od\fR. 446 .RE 447 448 .sp 449 .ne 2 450 .na 451 \fB\fB%OH\fR\fR 452 .ad 453 .RS 7n 454 Hour (24-hour clock) using the locale's alternate numeric symbols. 455 .RE 456 457 .sp 458 .ne 2 459 .na 460 \fB\fB%OI\fR\fR 461 .ad 462 .RS 7n 463 Hour (12-hour clock) using the locale's alternate numeric symbols. 464 .RE 465 466 .sp 467 .ne 2 468 .na 469 \fB\fB%Om\fR\fR 470 .ad 471 .RS 7n 472 Month using the locale's alternate numeric symbols. 473 .RE 474 475 .sp 476 .ne 2 477 .na 478 \fB\fB%OM\fR\fR 479 .ad 480 .RS 7n 481 Minutes using the locale's alternate numeric symbols. 482 .RE 483 484 .sp 485 .ne 2 486 .na 487 \fB\fB%OS\fR\fR 488 .ad 489 .RS 7n 490 Seconds using the locale's alternate numeric symbols. 491 .RE 492 493 .sp 494 .ne 2 495 .na 496 \fB\fB%OU\fR\fR 497 .ad 498 .RS 7n 499 Week number of the year (Sunday as the first day of the week) using the 500 locale's alternate numeric symbols. 501 .RE 502 503 .sp 504 .ne 2 505 .na 506 \fB\fB%Ow\fR\fR 507 .ad 508 .RS 7n 509 Number of the weekday (Sunday=0) using the locale's alternate numeric symbols. 510 .RE 511 512 .sp 513 .ne 2 514 .na 515 \fB\fB%OW\fR\fR 516 .ad 517 .RS 7n 518 Week number of the year (Monday as the first day of the week) using the 519 locale's alternate numeric symbols. 520 .RE 521 522 .sp 523 .ne 2 524 .na 525 \fB\fB%Oy\fR\fR 526 .ad 527 .RS 7n 528 Year (offset from \fB%C\fR) in the locale's alternate representation and using 529 the locale's alternate numeric symbols. 530 .RE 531 532 .SS "General Specifications" 533 .LP 534 A conversion specification that is an ordinary character is executed by 535 scanning the next character from the buffer. If the character scanned from the 536 buffer differs from the one comprising the specification, the specification 537 fails, and the differing and subsequent characters remain unscanned. 538 .sp 539 .LP 540 A series of specifications composed of \fB%n\fR, \fB%t\fR, white-space 541 characters or any combination is executed by scanning up to the first character 542 that is not white space (which remains unscanned), or until no more characters 543 can be scanned. White space is defined by \fBisspace\fR(3C). 544 .LP 545 Any other conversion specification is executed by scanning characters until a 546 character matching the next specification is scanned, or until no more 547 characters can be scanned. These characters, except the one matching the next 548 specification, are then compared to the locale values associated with the 549 conversion specifier. If a match is found, values for the appropriate 550 \fItm\fR structure members are set to values corresponding to the locale 551 information. If no match is found, \fBstrptime()\fR fails and no more 552 characters are scanned. 553 .sp 554 .LP 555 The month names, weekday names, era names, and alternate numeric symbols can 556 consist of any combination of upper and lower case letters. The user can 557 request that the input date or time specification be in a specific language by 558 setting the \fBLC_TIME\fR category using \fBsetlocale\fR(3C). 559 .SS "Non-zeroing Behavior" 560 .LP 561 In addition to the behavior described above by various standards, the Solaris 562 implementation of \fBstrptime()\fR provides the following extensions. These may 563 change at any time in the future. Portable applications should not depend on 564 these extended features: 565 .RS +4 566 .TP 567 .ie t \(bu 568 .el o 569 If \fB_STRPTIME_DONTZERO\fR is not defined, the \fBtm struct\fR is zeroed on 570 entry and \fBstrptime()\fR updates the fields of the \fBtm struct\fR associated 571 with the specifiers in the format string. 572 .RE 573 .RS +4 574 .TP 575 .ie t \(bu 576 .el o 577 If \fB_STRPTIME_DONTZERO\fR is defined, \fBstrptime()\fR does not zero the 578 \fBtm struct\fR on entry. Additionally, for some specifiers, \fBstrptime()\fR 579 will use some values in the input \fBtm struct\fR to recalculate the date and 580 re-assign the appropriate members of the \fBtm struct\fR. 581 .RE 582 .LP 583 The following describes extended features regardless of whether 584 \fB_STRPTIME_DONTZERO\fR is defined or not defined: 585 .RS +4 586 .TP 587 .ie t \(bu 588 .el o 589 If \fB%j\fR is specified, \fBtm_yday\fR is set; if year is given, and if month 590 and day are not given, \fBstrptime()\fR calculates and sets \fBtm_mon\fR, 591 \fBtm_mday\fR, and \fBtm_year\fR. 592 .RE 593 .RS +4 594 .TP 595 .ie t \(bu 596 .el o 597 If \fB%U\fR or \fB%W\fR is specified and if weekday and year are given and 598 month and day of month are not given, \fBstrptime()\fR calculates and sets 599 \fBtm_mon\fR, \fBtm_mday\fR, \fBtm_wday\fR, and \fBtm_year\fR. 600 .RE 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 .LP 612 The following describes extended features when \fB_STRPTIME_DONTZERO\fR is 613 defined: 614 .RS +4 615 .TP 616 .ie t \(bu 617 .el o 618 If \fB%C\fR is specified and \fB%y\fR is not specified, \fBstrptime()\fR 619 assumes the year offset of the year value of the \fBtm_year\fR member of the 620 input \fBtm struct\fR, then calculates the year and assigns \fBtm_year\fR. 621 .RE 622 .RS +4 623 .TP 624 .ie t \(bu 625 .el o 626 If \fB%j\fR is specified and neither \fB%y\fR, \fB%Y\fR, nor \fB%C\fR are 627 specified, and neither month nor day of month are specified, \fBstrptime()\fR 628 assumes the year value given by the value of the \fBtm_year\fR field of the 629 input \fBtm struct\fR. Then, in addition to setting \fBtm_yday\fR, 630 \fBstrptime()\fR uses day-of-year and year values to calculate the month and 631 day-of-month, and assigns \fBtm_month\fR and \fBtm_mday\fR. 632 .RE 633 .RS +4 634 .TP 635 .ie t \(bu 636 .el o 637 If \fB%U\fR or \fB%W\fR is specified, and if weekday and/or year are not given, 638 and month and day of month are not given, \fBstrptime()\fR will assume the 639 weekday value and/or the year value as the value of the \fBtm_wday\fR field 640 and/or \fBtm_year\fR field of the input \fBtm struct\fR. Then, 641 \fBstrptime()\fR will calculate the month and day-of-month and assign 642 \fBtm_month\fR, \fBtm_mday\fR, and/or \fBtm_year\fR. 643 .RE 644 .RS +4 645 .TP 646 .ie t \(bu 647 .el o 648 If \fB%p\fR is specified and if hour is not specified, \fBstrptime()\fR will 649 reference, and if needed, update the \fBtm_hour\fR member. If the \fBam_pm\fR 650 input is p.m. and the input \fBtm_hour\fR value is between 0 - 11, 651 \fBstrptime()\fR will add 12 hours and update \fBtm_hour\fR. If the 652 \fBam_pm\fR input is a.m. and input \fBtm_hour\fR value is between 12 - 23, 653 \fBstrptime()\fR will subtract 12 hours and update \fBtm_hour\fR. 654 .RE 655 .SH RETURN VALUES 656 .LP 657 Upon successful completion, \fBstrptime()\fR returns a pointer to the character 658 following the last character parsed. Otherwise, a null pointer is returned. 659 .SH USAGE 660 .LP 661 Several "same as" formats, and the special processing of white-space characters 662 are provided in order to ease the use of identical \fIformat\fR strings for 663 \fBstrftime\fR(3C) and \fBstrptime()\fR. 664 .LP 665 The \fBstrptime()\fR function tries to calculate \fBtm_year\fR, \fBtm_mon\fR, 666 and \fBtm_mday\fR when given incomplete input. This allows the \fBstruct tm\fR 667 created by \fBstrptime()\fR to be passed to \fBmktime\fR(3C) to produce a 668 \fBtime_t\fR value for dates and times that are representable by a 669 \fBtime_t\fR. As an example, since \fBmktime()\fR ignores \fBtm_yday\fR, 670 \fBstrptime()\fR calculates \fBtm_mon\fR and \fBtm_mday\fR as well as filling 671 in \fBtm_yday\fR when \fB%j\fR is specified without otherwise specifying a 672 month and day within month. 673 .SH ATTRIBUTES 674 .LP 675 See \fBattributes\fR(5) for descriptions of the following attributes: 676 .TS 677 box; 678 c | c 679 l | l . 680 ATTRIBUTE TYPE ATTRIBUTE VALUE 681 _ 682 CSI Enabled 683 _ 684 Interface Stability See below. 685 _ 686 MT-Level MT-Safe 687 _ 688 Standard See \fBstandards\fR(5) for \fBstrptime()\fR. 689 .TE 690 691 .LP 692 The \fBstrptime()\fR function is Standard. The \fBstrptime_l()\fR function 693 is Uncommitted. 694 .SH SEE ALSO 695 .LP 696 \fBctime\fR(3C), \fBgetdate\fR(3C), \fBisspace\fR(3C), \fBmktime\fR(3C), 697 \fBnewlocale\fR(3C), 698 \fBsetlocale\fR(3C), \fBstrftime\fR(3C), \fBuselocale\fR(3C), 699 \fBattributes\fR(5), \fBenviron\fR(5), 700 \fBstandards\fR(5)