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