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