1 '\" te 2 .\" Copyright (c) 2008, Sun Microsystems, Inc. All Rights Reserved. 3 .\" Copyright 1989 AT&T 4 .\" Portions Copyright (c) 1992, X/Open Company Limited. All Rights Reserved. 5 .\" 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 6 .\" http://www.opengroup.org/bookstore/. 7 .\" 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. 8 .\" This notice shall appear on any product containing this material. 9 .\" 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. 10 .\" 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. 11 .\" 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] 12 .TH STRFTIME 3C "Sep 5, 2006" 13 .SH NAME 14 strftime, cftime, ascftime \- convert date and time to string 15 .SH SYNOPSIS 16 .LP 17 .nf 18 #include <time.h> 19 20 \fBsize_t\fR \fBstrftime\fR(\fBchar *restrict\fR \fIs\fR, \fBsize_t\fR \fImaxsize\fR, 21 \fBconst char *restrict\fR \fIformat\fR, 22 \fBconst struct tm *restrict\fR \fItimeptr\fR); 23 .fi 24 25 .LP 26 .nf 27 \fBint\fR \fBcftime\fR(\fBchar *\fR\fIs\fR, \fBchar *\fR\fIformat\fR, \fBconst time_t *\fR\fIclock\fR); 28 .fi 29 30 .LP 31 .nf 32 \fBint\fR \fBascftime\fR(\fBchar *\fR\fIs\fR, \fBconst char *\fR\fIformat\fR, 33 \fBconst struct tm *\fR\fItimeptr\fR); 34 .fi 35 36 .SH DESCRIPTION 37 .sp 38 .LP 39 The \fBstrftime()\fR, \fBascftime()\fR, and \fBcftime()\fR functions place 40 bytes into the array pointed to by \fIs\fR as controlled by the string pointed 41 to by \fIformat\fR. The \fIformat\fR string consists of zero or more conversion 42 specifications and ordinary characters. A conversion specification consists of 43 a '\fB%\fR' (percent) character and one or two terminating conversion 44 characters that determine the conversion specification's behavior. All 45 ordinary characters (including the terminating null byte) are copied unchanged 46 into the array pointed to by \fIs\fR. If copying takes place between objects 47 that overlap, the behavior is undefined. For \fBstrftime()\fR, no more than 48 \fImaxsize\fR bytes are placed into the array. 49 .sp 50 .LP 51 If \fIformat\fR is \fB(char *)0\fR, then the locale's default format is used. 52 For \fBstrftime()\fR the default format is the same as \fB%c\fR; for 53 \fBcftime()\fR and \fBascftime()\fR the default format is the same as \fB%C\fR. 54 \fBcftime()\fR and \fBascftime()\fR first try to use the value of the 55 environment variable \fBCFTIME\fR, and if that is undefined or empty, the 56 default format is used. 57 .sp 58 .LP 59 Each conversion specification is replaced by appropriate characters as 60 described in the following list. The appropriate characters are determined by 61 the \fBLC_TIME\fR category of the program's locale and by the values contained 62 in the structure pointed to by \fItimeptr\fR for \fBstrftime()\fR and 63 \fBascftime()\fR, and by the time represented by \fIclock\fR for 64 \fBcftime()\fR. 65 .sp 66 .ne 2 67 .na 68 \fB\fB%%\fR\fR 69 .ad 70 .RS 6n 71 Same as \fB%\fR. 72 .RE 73 74 .sp 75 .ne 2 76 .na 77 \fB\fB%a\fR\fR 78 .ad 79 .RS 6n 80 Locale's abbreviated weekday name. 81 .RE 82 83 .sp 84 .ne 2 85 .na 86 \fB\fB%A\fR\fR 87 .ad 88 .RS 6n 89 Locale's full weekday name. 90 .RE 91 92 .sp 93 .ne 2 94 .na 95 \fB\fB%b\fR\fR 96 .ad 97 .RS 6n 98 Locale's abbreviated month name. 99 .RE 100 101 .sp 102 .ne 2 103 .na 104 \fB\fB%B\fR\fR 105 .ad 106 .RS 6n 107 Locale's full month name. 108 .RE 109 110 .SS "Default" 111 .sp 112 .ne 2 113 .na 114 \fB\fB%c\fR\fR 115 .ad 116 .RS 6n 117 Locale's appropriate date and time represented as: 118 .sp 119 .in +2 120 .nf 121 %a %b %d %H:%M:%S %Y 122 .fi 123 .in -2 124 125 This is the default behavior as well as standard-conforming behavior for 126 standards first supported by releases prior to Solaris 2.4. See 127 \fBstandards\fR(5). 128 .RE 129 130 .SS "Standard conforming" 131 .sp 132 .ne 2 133 .na 134 \fB\fB%c\fR\fR 135 .ad 136 .RS 6n 137 Locale's appropriate date and time represented as: 138 .sp 139 .in +2 140 .nf 141 %a %b %e %H:%M:%S %Y 142 .fi 143 .in -2 144 145 This is standard-conforming behavior for standards first supported by Solaris 146 2.4 through Solaris 10. 147 .RE 148 149 .SS "Default" 150 .sp 151 .ne 2 152 .na 153 \fB\fB%C\fR\fR 154 .ad 155 .RS 6n 156 Locale's date and time representation as produced by \fBdate\fR(1). 157 .sp 158 This is the default behavior as well as standard-conforming behavior for 159 standards first supported by releases prior to Solaris 2.4. 160 .RE 161 162 .SS "Standard conforming" 163 .sp 164 .ne 2 165 .na 166 \fB\fB%C\fR\fR 167 .ad 168 .RS 6n 169 Century number (the year divided by 100 and truncated to an integer as a 170 decimal number [01,99]). 171 .sp 172 This is standard-conforming behavior for standards first supported by Solaris 173 2.4 through Solaris 10. 174 .RE 175 176 .sp 177 .ne 2 178 .na 179 \fB\fB%d\fR\fR 180 .ad 181 .RS 6n 182 Day of month [01,31]. 183 .RE 184 185 .sp 186 .ne 2 187 .na 188 \fB\fB%D\fR\fR 189 .ad 190 .RS 6n 191 Date as \fB%m\fR/\fB%d\fR/\fB%y\fR. 192 .RE 193 194 .sp 195 .ne 2 196 .na 197 \fB\fB%e\fR\fR 198 .ad 199 .RS 6n 200 Day of month [1,31]; single digits are preceded by a space. 201 .RE 202 203 .sp 204 .ne 2 205 .na 206 \fB\fB%F\fR\fR 207 .ad 208 .RS 6n 209 Equivalent to \fB%Y\fR-\fB%m\fR-\fB%d\fR (the ISO 8601:2000 standard date 210 format). 211 .RE 212 213 .sp 214 .ne 2 215 .na 216 \fB\fB%g\fR\fR 217 .ad 218 .RS 6n 219 Week-based year within century [00,99]. 220 .RE 221 222 .sp 223 .ne 2 224 .na 225 \fB\fB%G\fR\fR 226 .ad 227 .RS 6n 228 Week-based year, including the century [0000,9999]. 229 .RE 230 231 .sp 232 .ne 2 233 .na 234 \fB\fB%h\fR\fR 235 .ad 236 .RS 6n 237 Locale's abbreviated month name. 238 .RE 239 240 .sp 241 .ne 2 242 .na 243 \fB\fB%H\fR\fR 244 .ad 245 .RS 6n 246 Hour (24-hour clock) [00,23]. 247 .RE 248 249 .sp 250 .ne 2 251 .na 252 \fB\fB%I\fR\fR 253 .ad 254 .RS 6n 255 Hour (12-hour clock) [01,12]. 256 .RE 257 258 .sp 259 .ne 2 260 .na 261 \fB\fB%j\fR\fR 262 .ad 263 .RS 6n 264 Day number of year [001,366]. 265 .RE 266 267 .sp 268 .ne 2 269 .na 270 \fB\fB%k\fR\fR 271 .ad 272 .RS 6n 273 Hour (24-hour clock) [0,23]; single digits are preceded by a space. 274 .RE 275 276 .sp 277 .ne 2 278 .na 279 \fB\fB%l\fR\fR 280 .ad 281 .RS 6n 282 Hour (12-hour clock) [1,12]; single digits are preceded by a space. 283 .RE 284 285 .sp 286 .ne 2 287 .na 288 \fB\fB%m\fR\fR 289 .ad 290 .RS 6n 291 Month number [01,12]. 292 .RE 293 294 .sp 295 .ne 2 296 .na 297 \fB\fB%M\fR\fR 298 .ad 299 .RS 6n 300 Minute [00,59]. 301 .RE 302 303 .sp 304 .ne 2 305 .na 306 \fB\fB%n\fR\fR 307 .ad 308 .RS 6n 309 Insert a NEWLINE. 310 .RE 311 312 .sp 313 .ne 2 314 .na 315 \fB\fB%p\fR\fR 316 .ad 317 .RS 6n 318 Locale's equivalent of either a.m. or p.m. 319 .RE 320 321 .sp 322 .ne 2 323 .na 324 \fB\fB%r\fR\fR 325 .ad 326 .RS 6n 327 Appropriate time representation in 12-hour clock format with \fB%p\fR. 328 .RE 329 330 .sp 331 .ne 2 332 .na 333 \fB\fB%R\fR\fR 334 .ad 335 .RS 6n 336 Time as \fB%H\fR:\fB%M\fR. 337 .RE 338 339 .sp 340 .ne 2 341 .na 342 \fB\fB%S\fR\fR 343 .ad 344 .RS 6n 345 Seconds [00,60]; the range of values is [00,60] rather than [00,59] to allow 346 for the occasional leap second. 347 .RE 348 349 .sp 350 .ne 2 351 .na 352 \fB\fB%t\fR\fR 353 .ad 354 .RS 6n 355 Insert a TAB. 356 .RE 357 358 .sp 359 .ne 2 360 .na 361 \fB\fB%T\fR\fR 362 .ad 363 .RS 6n 364 Time as \fB%H\fR:\fB%M\fR:\fB%S\fR. 365 .RE 366 367 .sp 368 .ne 2 369 .na 370 \fB\fB%u\fR\fR 371 .ad 372 .RS 6n 373 Weekday as a decimal number [1,7], with 1 representing Monday. See \fBNOTES\fR 374 below. 375 .RE 376 377 .sp 378 .ne 2 379 .na 380 \fB\fB%U\fR\fR 381 .ad 382 .RS 6n 383 Week number of year as a decimal number [00,53], with Sunday as the first day 384 of week 1. 385 .RE 386 387 .sp 388 .ne 2 389 .na 390 \fB\fB%V\fR\fR 391 .ad 392 .RS 6n 393 The ISO 8601 week number as a decimal number [01,53]. In the ISO 8601 394 week-based system, weeks begin on a Monday and week 1 of the year is the week 395 that includes both January 4th and the first Thursday of the year. If the 396 first Monday of January is the 2nd, 3rd, or 4th, the preceding days are part of 397 the last week of the preceding year. See \fBNOTES\fR below. 398 .RE 399 400 .sp 401 .ne 2 402 .na 403 \fB\fB%w\fR\fR 404 .ad 405 .RS 6n 406 Weekday as a decimal number [0,6], with 0 representing Sunday. 407 .RE 408 409 .sp 410 .ne 2 411 .na 412 \fB\fB%W\fR\fR 413 .ad 414 .RS 6n 415 Week number of year as a decimal number [00,53], with Monday as the first day 416 of week 1. 417 .RE 418 419 .sp 420 .ne 2 421 .na 422 \fB\fB%x\fR\fR 423 .ad 424 .RS 6n 425 Locale's appropriate date representation. 426 .RE 427 428 .sp 429 .ne 2 430 .na 431 \fB\fB%X\fR\fR 432 .ad 433 .RS 6n 434 Locale's appropriate time representation. 435 .RE 436 437 .sp 438 .ne 2 439 .na 440 \fB\fB%y\fR\fR 441 .ad 442 .RS 6n 443 Year within century [00,99]. 444 .RE 445 446 .sp 447 .ne 2 448 .na 449 \fB\fB%Y\fR\fR 450 .ad 451 .RS 6n 452 Year, including the century (for example 1993). 453 .RE 454 455 .sp 456 .ne 2 457 .na 458 \fB\fB%z\fR\fR 459 .ad 460 .RS 6n 461 Replaced by offset from UTC in ISO 8601:2000 standard format (\fB+hhmm\fR or 462 \fB-hhmm\fR), or by no characters if no time zone is determinable. For example, 463 "-0430" means 4 hours 30 minutes behind UTC (west of Greenwich). If 464 \fBtm_isdst\fR is zero, the standard time offset is used. If \fBtm_isdst\fR is 465 greater than zero, the daylight savings time offset if used. If \fBtm_isdst\fR 466 is negative, no characters are returned. 467 .RE 468 469 .sp 470 .ne 2 471 .na 472 \fB\fB%Z\fR\fR 473 .ad 474 .RS 6n 475 Time zone name or abbreviation, or no bytes if no time zone information exists. 476 .RE 477 478 .sp 479 .LP 480 If a conversion specification does not correspond to any of the above or to any 481 of the modified conversion specifications listed below, the behavior is 482 undefined and \fB0\fR is returned. 483 .sp 484 .LP 485 The difference between \fB%U\fR and \fB%W\fR (and also between modified 486 conversion specifications \fB%OU\fR and \fB%OW\fR) lies in which day is counted 487 as the first of the week. Week number 1 is the first week in January starting 488 with a Sunday for \fB%U\fR or a Monday for \fB%W\fR. Week number 0 contains 489 those days before the first Sunday or Monday in January for \fB%U\fR and 490 \fB%W\fR, respectively. 491 .SS "Modified Conversion Specifications" 492 .sp 493 .LP 494 Some conversion specifications can be modified by the \fBE\fR and \fBO\fR 495 modifiers to indicate that an alternate format or specification should be used 496 rather than the one normally used by the unmodified conversion specification. 497 If the alternate format or specification does not exist in the current locale, 498 the behavior will be as if the unmodified specification were used. 499 .sp 500 .ne 2 501 .na 502 \fB\fB%Ec\fR\fR 503 .ad 504 .RS 7n 505 Locale's alternate appropriate date and time representation. 506 .RE 507 508 .sp 509 .ne 2 510 .na 511 \fB\fB%EC\fR\fR 512 .ad 513 .RS 7n 514 Name of the base year (period) in the locale's alternate representation. 515 .RE 516 517 .sp 518 .ne 2 519 .na 520 \fB\fB%Eg\fR\fR 521 .ad 522 .RS 7n 523 Offset from \fB%EC\fR of the week-based year in the locale's alternative 524 representation. 525 .RE 526 527 .sp 528 .ne 2 529 .na 530 \fB\fB%EG\fR\fR 531 .ad 532 .RS 7n 533 Full alternative representation of the week-based year. 534 .RE 535 536 .sp 537 .ne 2 538 .na 539 \fB\fB%Ex\fR\fR 540 .ad 541 .RS 7n 542 Locale's alternate date representation. 543 .RE 544 545 .sp 546 .ne 2 547 .na 548 \fB\fB%EX\fR\fR 549 .ad 550 .RS 7n 551 Locale's alternate time representation. 552 .RE 553 554 .sp 555 .ne 2 556 .na 557 \fB\fB%Ey\fR\fR 558 .ad 559 .RS 7n 560 Offset from \fB%EC\fR (year only) in the locale's alternate representation. 561 .RE 562 563 .sp 564 .ne 2 565 .na 566 \fB\fB%EY\fR\fR 567 .ad 568 .RS 7n 569 Full alternate year representation. 570 .RE 571 572 .sp 573 .ne 2 574 .na 575 \fB\fB%Od\fR\fR 576 .ad 577 .RS 7n 578 Day of the month using the locale's alternate numeric symbols. 579 .RE 580 581 .sp 582 .ne 2 583 .na 584 \fB\fB%Oe\fR\fR 585 .ad 586 .RS 7n 587 Same as \fB%Od\fR. 588 .RE 589 590 .sp 591 .ne 2 592 .na 593 \fB\fB%Og\fR\fR 594 .ad 595 .RS 7n 596 Week-based year (offset from \fB%C\fR) in the locale's alternate representation 597 and using the locale's alternate numeric symbols. 598 .RE 599 600 .sp 601 .ne 2 602 .na 603 \fB\fB%OH\fR\fR 604 .ad 605 .RS 7n 606 Hour (24-hour clock) using the locale's alternate numeric symbols. 607 .RE 608 609 .sp 610 .ne 2 611 .na 612 \fB\fB%OI\fR\fR 613 .ad 614 .RS 7n 615 Hour (12-hour clock) using the locale's alternate numeric symbols. 616 .RE 617 618 .sp 619 .ne 2 620 .na 621 \fB\fB%Om\fR\fR 622 .ad 623 .RS 7n 624 Month using the locale's alternate numeric symbols. 625 .RE 626 627 .sp 628 .ne 2 629 .na 630 \fB\fB%OM\fR\fR 631 .ad 632 .RS 7n 633 Minutes using the locale's alternate numeric symbols. 634 .RE 635 636 .sp 637 .ne 2 638 .na 639 \fB\fB%OS\fR\fR 640 .ad 641 .RS 7n 642 Seconds using the locale's alternate numeric symbols. 643 .RE 644 645 .sp 646 .ne 2 647 .na 648 \fB\fB%Ou\fR\fR 649 .ad 650 .RS 7n 651 Weekday as a number in the locale's alternate numeric symbols. 652 .RE 653 654 .sp 655 .ne 2 656 .na 657 \fB\fB%OU\fR\fR 658 .ad 659 .RS 7n 660 Week number of the year (Sunday as the first day of the week) using the 661 locale's alternate numeric symbols. 662 .RE 663 664 .sp 665 .ne 2 666 .na 667 \fB\fB%Ow\fR\fR 668 .ad 669 .RS 7n 670 Number of the weekday (Sunday=0) using the locale's alternate numeric symbols. 671 .RE 672 673 .sp 674 .ne 2 675 .na 676 \fB\fB%OW\fR\fR 677 .ad 678 .RS 7n 679 Week number of the year (Monday as the first day of the week) using the 680 locale's alternate numeric symbols. 681 .RE 682 683 .sp 684 .ne 2 685 .na 686 \fB\fB%Oy\fR\fR 687 .ad 688 .RS 7n 689 Year (offset from \fB%C\fR) in the locale's alternate representation and using 690 the locale's alternate numeric symbols. 691 .RE 692 693 .SS "Selecting the Output Language" 694 .sp 695 .LP 696 By default, the output of \fBstrftime()\fR, \fBcftime()\fR, and 697 \fBascftime()\fR appear in U.S. English. The user can request that the output 698 of \fBstrftime()\fR, \fBcftime()\fR, or \fBascftime()\fR be in a specific 699 language by setting the \fBLC_TIME\fR category using \fBsetlocale()\fR. 700 .SS "Time Zone" 701 .sp 702 .LP 703 Local time zone information is used as though \fBtzset\fR(3C) were called. 704 .SH RETURN VALUES 705 .sp 706 .LP 707 The \fBstrftime()\fR, \fBcftime()\fR, and \fBascftime()\fR functions return the 708 number of characters placed into the array pointed to by \fIs\fR, not including 709 the terminating null character. If the total number of resulting characters 710 including the terminating null character is more than \fImaxsize\fR, 711 \fBstrftime()\fR returns \fB0\fR and the contents of the array are 712 indeterminate. 713 .SH EXAMPLES 714 .LP 715 \fBExample 1 \fRAn example of the \fBstrftime()\fR function. 716 .sp 717 .LP 718 The following example illustrates the use of \fBstrftime()\fR for the 719 \fBPOSIX\fR locale. It shows what the string in \fIstr\fR would look like if 720 the structure pointed to by \fItmptr\fR contains the values corresponding to 721 Thursday, August 28, 1986 at 12:44:36. 722 723 .sp 724 .in +2 725 .nf 726 \fBstrftime (str, strsize, "%A %b %d %j", tmptr)\fR 727 .fi 728 .in -2 729 730 .sp 731 .LP 732 This results in \fIstr\fR containing "Thursday Aug 28 240". 733 734 .SH ATTRIBUTES 735 .sp 736 .LP 737 See \fBattributes\fR(5) for descriptions of the following attributes: 738 .sp 739 740 .sp 741 .TS 742 box; 743 c | c 744 l | l . 745 ATTRIBUTE TYPE ATTRIBUTE VALUE 746 _ 747 CSI Enabled 748 _ 749 Interface Stability Committed 750 _ 751 MT-Level MT-Safe 752 _ 753 Standard See below. 754 .TE 755 756 .sp 757 .LP 758 For \fBstrftime()\fR, see \fBstandards\fR(5). 759 .SH SEE ALSO 760 .sp 761 .LP 762 \fBdate\fR(1), \fBctime\fR(3C), \fBmktime\fR(3C), \fBsetlocale\fR(3C), 763 \fBstrptime\fR(3C), \fBtzset\fR(3C), \fBTIMEZONE\fR(4), \fBzoneinfo\fR(4), 764 \fBattributes\fR(5), \fBenviron\fR(5), \fBstandards\fR(5) 765 .SH NOTES 766 .sp 767 .LP 768 The conversion specification for \fB%V\fR was changed in the Solaris 7 release. 769 This change was based on the public review draft of the ISO C9x standard at 770 that time. Previously, the specification stated that if the week containing 1 771 January had fewer than four days in the new year, it became week 53 of the 772 previous year. The ISO C9x standard committee subsequently recognized that that 773 specification had been incorrect. 774 .sp 775 .LP 776 The conversion specifications for \fB%g\fR, \fB%G\fR, \fB%Eg\fR, \fB%EG\fR, and 777 \fB%Og\fR were added in the Solaris 7 release. This change was based on the 778 public review draft of the ISO C9x standard at that time. These specifications 779 are evolving. If the ISO C9x standard is finalized with a different 780 conclusion, these specifications will change to conform to the ISO C9x standard 781 decision. 782 .sp 783 .LP 784 The conversion specification for \fB%u\fR was changed in the Solaris 8 release. 785 This change was based on the XPG4 specification. 786 .sp 787 .LP 788 If using the \fB%Z\fR specifier and \fBzoneinfo\fR timezones and if the input 789 date is outside the range 20:45:52 UTC, December 13, 1901 to 03:14:07 UTC, 790 January 19, 2038, the timezone name may not be correct.