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