strftime

Formats the time into an array under format control

Local Servers:nonblocking
Remote Servers:N/A
Classification:ANSI
Service:Time/Date Manipulation

Syntax

  #include <time.h> 
    
  size_t strftime  (  
     char              *s,   
     size_t             maxsize,   
     const char        *format,   
     const struct tm   *timeptr);
  

Parameters

s
(IN) Points to a character array.
maxsize
(IN) Specifies the maximum number of characters that can be placed in the array.
format
(IN) Points to the format control string.
timeptr
(IN) Points to the time argument.

Return Values

If the number of characters to be placed into the array is less than the value specified by the maxsize parameter, the number of characters placed into the array pointed to by the s parameter (not including the terminating NULL character) will be returned. Otherwise, a value of 0 is returned. If an error occurs, errno is set.

Remarks

strftime formats the time in the timeptr parameter into the array pointed to by the s parameter according to the format parameter and is not enabled for international use.

The format parameter string consists of zero or more directives and ordinary characters. A directive consists of a % character followed by a character that determines the substitution that is to take place. All ordinary characters are copied unchanged into the array. No more than the number of characters specified by the maxsize parameter are placed in the array.

Directive

Substitution

%a

Locale’s abbreviated weekday name

%A

Locale’s full weekday name

%b

Locale’s abbreviated month name

%B

Locale’s full month name

%c

Locale’s appropriate date and time representation

%C

Century number ("19" if year is 1997)

%d

Day of the month as a decimal number (01-31)

%D

Date in the format mm/dd/yy (POSIX)

%h

Locale’s abbreviated month name (POSIX)

%H

Hour (24-hour clock) as a decimal number (00-23)

%I

Hour (12-hour clock) as a decimal number (01-12)

%j

Day of the year as a decimal number (001-366)

%m

Month as a decimal number (01-12)

%M

Minute as a decimal number (00-59)

%n

Newline character (POSIX)

%p

Locale’s equivalent of either AM or PM. If linked with NWPRE.OBJ, a %P generates AM and PM while the %p generates am and pm.

%r

12-hour clock time (01-12) using the AM/PM notation in the format hh:mm:ss (POSIX). If linked with NWPRE.OBJ, a %R generates AM and PM while the %r generates am and pm.

%S

Second as a decimal number (00-59)

%t

Tab character (POSIX)

%T

24-hour clock time in the format hh:mm:ss (POSIX)

%U

Week number of the year as a decimal number (00-52) where Sunday is the first day of the week

%w

Weekday as a decimal number (0-6) where 0 is Sunday

%W

Week number of the year as a decimal number (00-52) where Monday is the first day of the week

%x

Locale’s appropriate date representation

%X

Locale’s appropriate time representation

%y

Year without century as a decimal number (00-99)

%Y

Year with century as a decimal number

%Z

Timezone name, or by no characters if no timezone exists

%%

Character %

See Also

asctime, asctime_r, clock, ctime, ctime_r, difftime, gmtime, gmtime_r, localtime, localtime_r, mktime, setlocale (Internationalization), time

Example

  #include <stdio.h>  
  #include <time.h>  
   
  main()  
  {  
     time_t time_of_day;  
     char buffer[80];  
     time_of_day = time (NULL);  
     strftime (buffer, 80, "Today is %A %B %d, %Y",  
        localtime (&time_of_day) );  
     printf ("%s\n", buffer);  
  }
  

produces the following:

  Today is Friday December 25, 1990