Formats


The os_date , os_time , and os_time_and_date classes use a format specifier when an instance of the class is streamed using operator<< or is converted into a string using to_string() . The default formats are listed in the following table.
 
Class Default format

os_time

"%X"

os_date

"%x"

os_time_and_date

"%c"

Each class defines default_format() access functions that access and modify its format specifier. The following table lists acceptable format specifiers.
 
Place Holder Meaning

%%

same as %

%a

day of week, using locale's abbreviated weekday names

%A

day of week, using locale's full weekday names

%b

month, using locale's abbreviated month names

%B

month, using locale's full month names

%c

date and time as %x %X

%C

century, 1992 becomes 19 (-47 to 327)

%d

two-digit day of month (01 to 31)

%D

date as %m/%d/%y

%e

two-digit day of month, single digits are preceded by a blank (1 to 31)

%f

if year < 1000, then "%s %P", else "%s"

%H

two-digit hour (00 to 23)

%I

two-digit hour (01 to 12)

%j

three-digit day number of year (001 to 366)

%k

two-digit hour, single digits are preceded by a blank (0 to 23)

%l

two-digit hour, single-digits are preceded by a blank (1 to 12)

%m

month number (01 to 12)

%M

minute (00 to 59)

%n

newline, same as \n

%p

locale's equivalent of a.m. or p.m., whichever is appropriate

%P

A.D. or B.C.

%q

microseconds (000000 to 999999)

%r

time as %I:%M:%S %p

%s

positive year, -4 becomes 4 (1 to 32766)

%S

seconds (00 to 59)

%t

tab, same as \t

%T

time as %H:%M:%S

%U

week number of year, Sunday is the first day of the week (00 to 53)

%w

day of week; Sunday is day 0 (0 to 6)

%W

week number of year, Monday is the first day of the week (00 to 53)

%x

date, using locale's date format

%X

time, using locale's time format

%y

year within century (00 to 99)

%Y

year, including century (-4713 to 32766)

%Z

time zone abbreviation

When specifying a format, supply the placeholders in a single string in a manner similar to printf() . When displaying an object, any characters not recognized as placeholders remain in the output. Note that the %U and %W fields consider the first week of the year to be the first week in January that contains four or more days.

Example <ospace/time/examples/format1.cpp>
#include <iostream>
#include <ospace/time.h>

void
main()
  {
  os_time_toolkit initialize;

  os_time time( 11, 4, 22 );
  cout << "time = " << time.to_string( "%S,%M,%H" ) << endl;
  cout << "time = " << time << endl;
  os_time::default_format( "%S,%M,%H" ); // Change format.
  cout << "time = " << time << endl;

  os_date date( 2, 12, 1965 );
  cout << "date = " << date.to_string( "%B %d %y (%Z)" ) << endl;
  cout << "date = " << date << endl;
  os_date::default_format( "%B %d %y (%Z)" ); // Change format.
  cout << "date = " << date << endl;
  }

time = 22,04,11
time = 11:04:22.000000
time = 22,04,11
date = February 12 65 (CST6)
date = 02/12/65
date = February 12 65 (CST6)

Copyright©1994-2026 Recursion Software LLC
All Rights Reserved - For use by licensed users only.