1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497
|
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE library PUBLIC "-//Boost//DTD BoostBook XML V1.0//EN"
"../../../tools/boostbook/dtd/boostbook.dtd">
<!-- Copyright (c) 2005 CrystalClear Software, Inc.
Subject to the Boost Software License, Version 1.0.
(See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
-->
<section id="date_time.format_flags">
<title>Format Flags</title>
<para>Many of the format flags this new system uses for output are those used by <code>strftime(...)</code>, but not all. Some new flags have been added, and others overridden. The input system supports only specific flags, therefore, not all flags that work for output will work with input (we are currently working to correct this situation).</para>
<para>The following tables list the all the flags available for both date_time IO as well as strftime. Format flags marked with a single asterisk (*) have a behavior unique to date_time. Those flags marked with an exclamation point (!) are not usable for input (at this time). The first table is for dates, and the second table is for times.
</para>
<para>
<anchor id="date_time_io.date_format_flags" />
Date Facet Format Flags
<informaltable frame="all">
<tgroup cols="2">
<thead>
<row>
<entry valign="top" morerows="1">Format Specifier</entry>
<entry>Description</entry>
</row>
<row>
<entry>Example</entry>
</row>
</thead>
<tbody>
<row>
<entry valign="top" morerows="1"><screen>%a</screen></entry>
<entry>Abbreviated weekday name</entry>
</row>
<row>
<entry><screen>"Mon" => Monday</screen></entry>
</row>
<row>
<entry valign="top" morerows="1"><screen>%A</screen></entry>
<entry>Long weekday name</entry>
</row>
<row>
<entry><screen>"Monday"</screen></entry>
</row>
<row>
<entry valign="top" morerows="1"><screen>%b</screen></entry>
<entry>Abbreviated month name</entry>
</row>
<row>
<entry><screen>"Feb" => February</screen></entry>
</row>
<row>
<entry valign="top" morerows="1"><screen>%B</screen></entry>
<entry>Full month name</entry>
</row>
<row>
<entry><screen>"February"</screen></entry>
</row>
<row>
<entry valign="top" morerows="1"><screen>%c !</screen></entry>
<entry>The preferred date and time representation for the current locale.</entry>
</row>
<row>
<entry><screen></screen></entry>
</row>
<row>
<entry valign="top" morerows="1"><screen>%C !</screen></entry>
<entry>The century number (year/100) as a 2-digit integer.</entry>
</row>
<row>
<entry><screen></screen></entry>
</row>
<row>
<entry valign="top" morerows="1"><screen>%d</screen></entry>
<entry>Day of the month as decimal 01 to 31</entry>
</row>
<row>
<entry><screen></screen></entry>
</row>
<row>
<entry valign="top" morerows="1"><screen>%D !</screen></entry>
<entry>Equivalent to %m/%d/%y</entry>
</row>
<row>
<entry><screen></screen></entry>
</row>
<row>
<entry valign="top" morerows="1"><screen>%e</screen></entry>
<entry>Like %d, the day of the month as a decimal number, but a leading zero is replaced by a space</entry>
</row>
<row>
<entry><screen></screen></entry>
</row>
<row>
<entry valign="top" morerows="1"><screen>%G !</screen></entry>
<entry>This has the same format and value as %y, except that if the ISO week number belongs to the previous or next year, that year is used instead.</entry>
</row>
<row>
<entry><screen></screen></entry>
</row>
<row>
<entry valign="top" morerows="1"><screen>%g !</screen></entry>
<entry>Like %G, but without century.</entry>
</row>
<row>
<entry><screen></screen></entry>
</row>
<row>
<entry valign="top" morerows="1"><screen>%h !</screen></entry>
<entry> Equivalent to %b</entry>
</row>
<row>
<entry><screen></screen></entry>
</row>
<row>
<entry valign="top" morerows="1"><screen>%j</screen></entry>
<entry>Day of year as decimal from 001 to 366 for leap years, 001 - 365 for non-leap years.</entry>
</row>
<row>
<entry><screen>"060" => Feb-29</screen></entry>
</row>
<row>
<entry valign="top" morerows="1"><screen>%m</screen></entry>
<entry>Month name as a decimal 01 to 12</entry>
</row>
<row>
<entry><screen>"01" => January</screen></entry>
</row>
<row>
<entry valign="top" morerows="1"><screen>%u !</screen></entry>
<entry>The day of the week as a decimal, range 1 to 7, Monday being 1.</entry>
</row>
<row>
<entry><screen></screen></entry>
</row>
<row>
<entry valign="top" morerows="1"><screen>%U</screen></entry>
<entry>The week number of the current year as a decimal number, range 00 to 53, starting with the first Sunday as the first day of week 01. In 2005, Jan 1st falls on a Saturday, so therefore it falls within week 00 of 2005 (week 00 spans 2004-Dec-26 to 2005-Jan-01. This also happens to be week 53 of 2004).</entry>
</row>
<row>
<entry><screen>date d(2005, Jan, 1); // Saturday
// with format %U
ss << d; // "00"
d += day(1); // Sunday
ss << d; // "01" beginning of week 1</screen></entry>
</row>
<row>
<entry valign="top" morerows="1"><screen>%V !</screen></entry>
<entry>The ISO 8601:1988 week number of the current year as a decimal number, range 01 to 53, where week 1 is the first week that has at least 4 days in the current year, and with Monday as the first day of the week.</entry>
</row>
<row>
<entry><screen></screen></entry>
</row>
<row>
<entry valign="top" morerows="1"><screen>%w</screen></entry>
<entry>Weekday as decimal number 0 to 6</entry>
</row>
<row>
<entry><screen>"0" => Sunday</screen></entry>
</row>
<row>
<entry valign="top" morerows="1"><screen>%W</screen></entry>
<entry>Week number 00 to 53 where Monday is first day of week 1</entry>
</row>
<row>
<entry><screen>date d(2005, Jan, 2); // Sunday
// with format %W
ss << d; // "00"
d += day(1); // Monday
ss << d; // "01" beginning of week 1</screen></entry>
</row>
<row>
<entry valign="top" morerows="1"><screen>%x</screen></entry>
<entry>Implementation defined date format from the locale.</entry>
</row>
<row>
<entry><screen>date d(2005,Oct,31);
date_facet* f = new date_facet("%x");
locale loc = locale(locale("en_US"), f);
cout.imbue(loc);
cout << d; // "10/31/2005"
loc = locale(locale("de_DE"), f);
cout.imbue(loc);
cout << d; // "31.10.2005"</screen></entry>
</row>
<row>
<entry valign="top" morerows="1"><screen>%y</screen></entry>
<entry>Two digit year</entry>
</row>
<row>
<entry><screen>"05" => 2005</screen></entry>
</row>
<row>
<entry valign="top" morerows="1"><screen>%Y</screen></entry>
<entry>Four digit year</entry>
</row>
<row>
<entry><screen>"2005"</screen></entry>
</row>
<row>
<entry valign="top" morerows="1"><screen>%Y-%b-%d</screen></entry>
<entry>Default date format</entry>
</row>
<row>
<entry><screen>"2005-Apr-01"</screen></entry>
</row>
<row>
<entry valign="top" morerows="1"><screen>%Y%m%d</screen></entry>
<entry>ISO format</entry>
</row>
<row>
<entry><screen>"20050401"</screen></entry>
</row>
<row>
<entry valign="top" morerows="1"><screen>%Y-%m-%d</screen></entry>
<entry>ISO extended format</entry>
</row>
<row>
<entry><screen>"2005-04-01"</screen></entry>
</row>
</tbody>
</tgroup>
</informaltable>
<anchor id="date_time_io.time_format_flags" />
Time Facet Format Flags
<informaltable frame="all">
<tgroup cols="2">
<thead>
<row>
<entry valign="top" morerows="1">Format Specifier</entry>
<entry>Description</entry>
</row>
<row>
<entry>Example</entry>
</row>
</thead>
<tbody>
<row>
<entry valign="top" morerows="1"><screen>%- *!</screen></entry>
<entry>Placeholder for the sign of a duration. Only displays when the duration is negative.</entry>
</row>
<row>
<entry><screen>"-13:15:16"</screen></entry>
</row>
<row>
<entry valign="top" morerows="1"><screen>%+ *!</screen></entry>
<entry>Placeholder for the sign of a duration. Always displays for both positive and negative.</entry>
</row>
<row>
<entry><screen>"+13:15:16"</screen></entry>
</row>
<row>
<entry valign="top" morerows="1"><screen>%f</screen></entry>
<entry>Fractional seconds are always used, even when their value is zero</entry>
</row>
<row>
<entry><screen>"13:15:16.000000"</screen></entry>
</row>
<row>
<entry valign="top" morerows="1"><screen>%F *</screen></entry>
<entry>Fractional seconds are used only when their value is not zero.</entry>
</row>
<row>
<entry><screen>"13:15:16"
"05:04:03.001234"
</screen></entry>
</row>
<row>
<entry valign="top" morerows="1"><screen>%I !</screen></entry>
<entry>The hour as a decimal number using a 12-hour clock</entry>
</row>
<row>
<entry></entry>
</row>
<row>
<entry valign="top" morerows="1"><screen>%k !</screen></entry>
<entry>The hour (24-hour clock) as a decimal number (range 0 to 23); single digits are preceded by a blank.</entry>
</row>
<row>
<entry><screen></screen></entry>
</row>
<row>
<entry valign="top" morerows="1"><screen>%l !</screen></entry>
<entry>The hour (12-hour clock) as a decimal number (range 1 to 12); single digits are preceded by a blank.</entry>
</row>
<row>
<entry><screen></screen></entry>
</row>
<row>
<entry valign="top" morerows="1"><screen>%p !</screen></entry>
<entry>Either `AM' or `PM' according to the given time value, or the corresponding strings for the current locale.</entry>
</row>
<row>
<entry><screen></screen></entry>
</row>
<row>
<entry valign="top" morerows="1"><screen>%P !</screen></entry>
<entry>Like %p but in lowercase: `am' or `pm' or a corresponding string for the current locale.</entry>
</row>
<row>
<entry><screen></screen></entry>
</row>
<row>
<entry valign="top" morerows="1"><screen>%r !</screen></entry>
<entry>The time in a.m. or p.m. notation. In the POSIX locale this is equivalent to `%I:%M:%S %p'</entry>
</row>
<row>
<entry><screen></screen></entry>
</row>
<row>
<entry valign="top" morerows="1"><screen>%R !</screen></entry>
<entry>The time in 24-hour notation (%H:%M)</entry>
</row>
<row>
<entry><screen></screen></entry>
</row>
<row>
<entry valign="top" morerows="1"><screen>%s *</screen></entry>
<entry>Seconds with fractional seconds.</entry>
</row>
<row>
<entry><screen>"59.000000"</screen></entry>
</row>
<row>
<entry valign="top" morerows="1"><screen>%S</screen></entry>
<entry>Seconds only</entry>
</row>
<row>
<entry><screen>"59"</screen></entry>
</row>
<row>
<entry valign="top" morerows="1"><screen>%T !</screen></entry>
<entry>The time in 24-hour notation (%H:%M:%S)</entry>
</row>
<row>
<entry><screen></screen></entry>
</row>
<row>
<entry valign="top" morerows="1"><screen>%q</screen></entry>
<entry>ISO time zone (output only). This flag is ignored when using the time_facet with a ptime.</entry>
</row>
<row>
<entry><screen>"-0700" // Mountain Standard Time</screen></entry>
</row>
<row>
<entry valign="top" morerows="1"><screen>%Q</screen></entry>
<entry>ISO extended time zone (output only). This flag is ignored when using the time_facet with a ptime.</entry>
</row>
<row>
<entry><screen>"-05:00" // Eastern Standard Time</screen></entry>
</row>
<row>
<entry valign="top" morerows="1"><screen>%z *!</screen></entry>
<entry>Abbreviated time zone (output only). This flag is ignored when using the time_facet with a ptime.</entry>
</row>
<row>
<entry><screen>"MST" // Mountain Standard Time</screen></entry>
</row>
<row>
<entry valign="top" morerows="1"><screen>%Z *!</screen></entry>
<entry>Full time zone name (output only). This flag is ignored when using the time_facet with a ptime.</entry>
</row>
<row>
<entry><screen>"EDT" // Eastern Daylight Time</screen></entry>
</row>
<row>
<entry valign="top" morerows="1"><screen>%ZP *</screen></entry>
<entry>Posix time zone string (available to both input and output). This flag is ignored when using the time_facet with a ptime. For complete details on posix time zone strings, see <link linkend="date_time.local_time.posix_time_zone">posix_time_zone class</link>.</entry>
</row>
<row>
<entry><screen>"EST-05EDT+01,M4.1.0/02:00,M10.5.0/02:00"</screen></entry>
</row>
<row>
<entry valign="top" morerows="1"><screen>%x %X</screen></entry>
<entry>Implementation defined date/time format from the locale.</entry>
</row>
<row>
<entry><screen>date d(2005,Oct,31);
ptime pt(d, hours(20));
time_facet* f = new time_facet("%x %X");
locale loc = locale(locale("en_US"), f);
cout.imbue(loc);
cout << pt; // "10/31/2005 08:00:00 PM"
loc = locale(locale("de_DE"), f);
cout.imbue(loc);
cout << pt; // "31.10.2005 20:00:00"</screen></entry>
</row>
<row>
<entry valign="top" morerows="1"><screen>%Y%m%dT%H%M%S%F%q</screen></entry>
<entry>ISO format</entry>
</row>
<row>
<entry><screen>"20051015T131211-0700"
// Oct 15, 2005 13:12:11 MST
</screen></entry>
</row>
<row>
<entry valign="top" morerows="1"><screen>%Y-%m-%d %H:%M:%S%F%Q</screen></entry>
<entry>Extended ISO format</entry>
</row>
<row>
<entry><screen>"2005-10-15 13:12:11-07:00"</screen></entry>
</row>
<row>
<entry valign="top" morerows="1"><screen>%Y-%b-%d %H:%M:%S%F %z</screen></entry>
<entry>Default format used when outputting ptime and local_date_time.</entry>
</row>
<row>
<entry><screen>"2005-Oct-15 13:12:11 MST"</screen></entry>
</row>
<row>
<entry valign="top" morerows="1"><screen>%Y-%b-%d %H:%M:%S%F %ZP</screen></entry>
<entry>Default format used when inputting ptime and local_date_time.</entry>
</row>
<row>
<entry><screen>"2005-Oct-15 13:12:11 MST-07"</screen></entry>
</row>
<row>
<entry valign="top" morerows="1"><screen>%-%H:%M:%S%F !</screen></entry>
<entry>Default time_duration format for output. Sign will only be displayed for negative durations.</entry>
</row>
<row>
<entry><screen>"-13:14:15.003400"</screen></entry>
</row>
<row>
<entry valign="top" morerows="1"><screen>%H:%M:%S%F</screen></entry>
<entry>Default time_duration format for input.</entry>
</row>
<row>
<entry><screen>"13:14:15.003400"</screen></entry>
</row>
</tbody>
</tgroup>
</informaltable>
</para>
<para>* Signifies flags that have a behavior unique to <code>date_time</code>.</para>
<para>! Signifies flags that currently do not work for input.</para>
</section>
|