PHP strftime()Functions

PHP Date/TimePHP Date/Time Reference Manual

Example

Format local date and time according to locale settings:

<?php echo(strftime("%B %d %Y, %X %Z",mktime(20,0,0,12,31,98))."<br>"); setlocale(LC_ALL,"hu_HU.UTF8"); echo(strftime("%Y. %B %d. %A. %X %Z")); ?>

Run example »

Definition and Usage

The strftime() function formats a local date and time according to locale settings.

Tip:Please refer to the gmstrftime()function, which formats GMT/UTC time/date according to locale settings.

Syntax

strftime(format,timestamp);

Parameters Description
format Required. Specifies how to return the result:
  • %a - Abbreviated weekday name
  • %A - Full weekday name
  • %b - Abbreviated month name
  • %B - Full month name
  • %c - Preferred date and time representation
  • %C - Number representing the century (year divided by 100, range 00 to 99)
  • %d - Day of the month (01 to 31)
  • %D - Time format, same as %m/%d/%y notation
  • %e - Day of the month (1 to 31)
  • %g - Similar to %G notation, but without the century
  • %G - 4-digit year corresponding to the ISO week number (see %V)
  • %h - Same as %b notation
  • %H - Hour, using 24-hour format (00 to 23)
  • %I - Hour, using 12-hour format (01 to 12)
  • %j - Day of the year (001 to 366)
  • %m - Month (01 to 12)
  • %M - Minutes
  • %n - Newline character
  • %p - am or pm corresponding to the given time value
  • %r - Time notation in a.m. and p.m. format
  • %R - Time notation in 24-hour format
  • %S - Seconds
  • %t - Tab character
  • %T - Current time, same as %H:%M:%S notation
  • %u - Numeric representation of the day of the week (1 to 7), Monday = 1. Warning: On Sun Solaris systems, Sunday = 1
  • %U - Number of weeks in the year, starting with the first Sunday as the first day of the first week
  • %V - ISO 8601 week number of the year (01 to 53), week 1 is the first week of the year that has at least four days, with Monday as the first day of the week
  • %W - Number of weeks in the year, starting with the first Monday as the first day of the first week
  • %w - Day of the week as a decimal number, Sunday = 0
  • %x - Preferred date representation, without time
  • %X - Preferred time representation, without date
  • %y - Year representation without century (range 00 to 99)
  • %Y - Year representation including century
  • %Z or %z - Time zone name or abbreviation
  • %% - Outputs a % character
timestamp Optional. Specifies the Unix timestamp of the date/time to be formatted. Defaults to the current time (time()).

Technical Details

Return value: Returns a string formatted according toformatusing the giventimestampformat. Month and weekday names and other language-dependent strings obey the current locale set by setlocale().
PHP Version: 4+
Changelog: PHP 5.1.0: Added E_STRICT and E_NOTICE timezone errors.


PHP Date/TimePHP Date/Time Reference Manual Other Extensions