Example
Formats local date and time based on 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”)); ?> |
Definition and Usage
The strftime()
function formats local time and/or date according to locale settings.
Tip: Consider using the gmstrftime()
function for formatting GMT/UTC time and/or date according to locale settings.
Syntax
strftime(format, timestamp) |
Parameter Values
Parameter
|
Description
|
format
|
Required. Specifies the format of 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: Century number (year divided by 100, range 00 to 99)
- %d: Day of the month (01 to 31)
- %D: Same as %m/%d/%y
- %e: Day of the month (1 to 31)
- %g: Year without the century, like %G
- %G: 4-digit year corresponding to the ISO week number (see %V)
- %h: Same as %b
- %H: Hour in 24-hour format (00 to 23)
- %I: Hour in 12-hour format (01 to 12)
- %j: Day of the year (001 to 366)
- %m: Month (01 to 12)
- %M: Minute
- %n: Newline character
- %p: AM or PM based on the time
- %r: Time in a.m. and p.m. notation
- %R: Time in 24-hour notation
- %S: Second
- %t: Tab character
- %T: Current time, equivalent to %H:%M:%S
- %u: Weekday as a number (1 to 7), with Monday=1 (Note: On Sun Solaris, Sunday=1)
- %U: Week number of 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), where week 1 is the first week with at least 4 days in the current year, and Monday is the first day of the week
- %W: Week number of the year, starting with the first Monday as the first day of the first week
- %w: Day of the week as a decimal, Sunday=0
- %x: Preferred date representation without the time
- %X: Preferred time representation without the date
- %y: Year without the century (00 to 99)
- %Y: Year including the century
- %Z or %z: Time zone or name or abbreviation
- %%: Literal % character
|
timestamp
|
Optional. Specifies a Unix timestamp to format. Defaults to the current local time (time() ) if not provided.
|
Technical Details
Return Value:
|
Returns a string formatted according to the specified format using the given timestamp. Month and weekday names, along with other locale-dependent strings, follow the current locale settings configured with setlocale() .
|
PHP Version:
|
4+
|
PHP Changelog:
|
PHP 5.1: Now generates E_STRICT and E_NOTICE errors for time zone issues.
|