Print this page
4378 Clean up %C in *time() functions
438 need documentation for strftime %s flag
   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 


  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 


 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


 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


 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,


   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 


  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 


 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


 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


 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,