strftime : strftime « time.h « C Tutorial

C Tutorial
1. Language
2. Data Type
3. String
4. printf scanf
5. Operator
6. Statement
7. Array
8. Function
9. Structure
10. Pointer
11. Memory
12. Preprocessor
13. File
14. Data Structure
15. Search Sort
16. Wide Character String
17. assert.h
18. ctype.h
19. math.h
20. setjmp.h
21. signal.h
22. stdio.h
23. stdlib.h
24. string.h
25. time.h
26. wctype.h
Java
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
C# / C Sharp
C# / CSharp Tutorial
ASP.Net
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C++
C++ Tutorial
PHP
Python
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
C Tutorial » time.h » strftime 
25. 11. 1. strftime
ItemValue
Header filetime.h
Declarationsize_t strftime(char *str, size_t maxsize, const char *fmt, const struct tm *time);
Functionformat time and date into a string


  1. The strftime() function works a little like sprintf().
  2. The strftime() function returns the number of characters stored in the string pointed to by str or zero if an error occurs.
CommandReplaced By
%aAbbreviated weekday name
%AFull weekday name
%bAbbreviated month name
%BFull month name
%cStandard date and time string
%CLast two digits of year
%dDay of month as a decimal (1-31)
%Dmonth/day/year (added by C99)
%eDay of month as a decimal (1-31) in a two-character field (added by C99)
%Fyear-month-day (added by C99)
%gLast two digits of year using a week-based year (added by C99)
%GThe year using a week-based year (added by C99)
%hAbbreviated month name (added by C99)
%HHour (0-23)
%IHour (1-12)
%jDay of year as a decimal (1-366)
%mMonth as decimal (1-12)
%MMinute as decimal (0-59)
%nA newline (added by C99)
%pLocale's equivalent of AM or PM
%r12-hour time (added by C99)
%Rhh:mm (added by C99)
%SSecond as decimal (0-60)
%tHorizontal tab (added by C99)
%Thh:mm:ss (added by C99)
%uDay of week; Monday is first day of week (0-53) (added by C99)
%UWeek of year, Sunday being first day (0-53)
%VWeek of year using a week-based year (added by C99)
%wWeekday as a decimal (0-6, Sunday being 0)
%WWeek of year, Monday being first day (0-53)
%xStandard date string
%XStandard time string
%yYear in decimal without century (0-99)
%YYear including century as decimal
%zOffset from UTC (added by C99)
%ZTime zone name
%%The percent sign


  1. The E can modify c, C, x, X, y, Y, d, e, and H.
  2. The O can modify I, m, M, S, u, U, V, w, W, and y.

A week-based year is used by the %g, %G, and %V format commands.

With this representation, Monday is the first day of the week, and the first week of a year must include January 4.

#include <time.h>
  #include <stdio.h>

  int main(void)
  {
    struct tm *ptr;
    time_t lt;
    char str[80];

    lt = time(NULL);
    ptr = localtime(&lt);

    strftime(str, 100"It is now %H %p.", ptr);
    printf(str);

    return 0;
  }
It is now 16 PM.
25. 11. strftime
25. 11. 1. strftime
w___w_w.__j_a___v___a2_s_.__c___o__m__ | Contact Us
Copyright 2003 - 08 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.