delorie.com/djgpp/doc/libc/libc_760.html   search  
libc.a reference

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

strftime

Syntax

 
#include <time.h>

size_t strftime(char *buf, size_t n, const char *format,
                const struct tm *time_info);

Description

This function formats the time data in time_info according to the given format and stores it in buf, not exceeding n bytes.

The format string is like printf in that any character other than % is added to the output string, and for each character following a % a pattern is added to the string as follows, with the examples as if the time was Friday, October 1, 1993, at 03:30:34 PM EDT:

%A

The full weekday name (Friday)

%a

The abbreviated weekday name (Fri)

%B

The full month name (October)

%b
%h

The abbreviated month name (Oct)

%C

Short for %a %b %e %H:%M:%S %Y (Fri Oct 1 15:30:34 1993)

%c

Short for %m/%d/%y %H:%M:%S (10/01/93 15:30:34)

%e

The day of the month, blank padded to two characters ( 2)

%D

Short for %m/%d/%y (10/01/93)

%d

The day of the month, zero padded to two characters (02)

%H

The hour (0-24), zero padded to two characters (15)

%I

The hour (1-12), zero padded to two characters (03)

%j

The Julian day, zero padded to three characters (275)

%k

The hour (0-24), space padded to two characters (15)

%l

The hour (1-12), space padded to two characters( 3)

%M

The minutes, zero padded to two characters (30)

%m

The month (1-12), zero padded to two characters (10)

%n

A newline (\n)

%p

AM or PM (PM)

%R

Short for %H:%M (15:30)

%r

Short for %I:%M:%S %p (03:30:35 PM)

%S

The seconds, zero padded to two characters (35)

%T

Short for %H:%M:%S (15:30:35)

%t

A tab (\t)

%U

The week of the year, with the first week defined by the first Sunday of the year, zero padded to two characters (39)

%u

The day of the week (1-7) (6)

%W

The week of the year, with the first week defined by the first Monday of the year, zero padded to two characters (39)

%w

The day of the week (0-6) (5)

%x

Date represented according to the current locale.

%X

Time represented according to the current locale.

%y

The year (00-99) of the century (93)

%Y

The year, zero padded to four digits (1993)

%Z

The timezone abbreviation (EDT)

%%

A percent symbol (%)

Return Value

The number of characters stored.

Portability

ANSI/ISO C C89; C99
POSIX 1003.2-1992; 1003.1-2001

Example

 
time_t now = time (NULL);
struct tm *t = localtime (&now);
char buf[100];
/* Print today's date e.g. "January 31, 2001".  */
strftime (buf, 100, "%B %d, %Y", t);


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

  webmaster     delorie software   privacy  
  Copyright © 2004     Updated Apr 2004