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