PHP: strftime() function
Description
The strftime() function is used to get a local time/date format according to the localization settings.
Version:
(PHP 4 and above)
Syntax:
strftime(format, timestamp )
Parameters:
Name | Description | Required / Optional |
Type |
---|---|---|---|
format | Day : %a - Short day abbreviation ( Sun through Sat) %A - A full day name ( Sunday through Saturday) %d - Numeric day of the month with leading zeros (01 to 31) %e - Day of the month without leading zeros (1 to 31 ) %j - Day of the year, 3 digits with leading zeros (001 to 366) %u - ISO-8601 numeric day of the week 1 (for Monday) through 7 (for Sunday) %w - Numeric day of the week 0 (for Sunday) through 6 (for Saturday) Week : %U - Week number of a specified year, starting with the first Sunday as the first week 13 (for the 13th full week of the year) %V - ISO-8601:1988 week number of a specific year, starting the first week of the year with at least 4 weekdays. Example : Monday being the start of the week 01 through 53 %W - Numeric representation of week number of year. Week starting from Monday Month : %b - Abbreviated month name (Jan through Dec) %B - Full month name (January through December) %h - Abbreviated month name (Jan through Dec) %m - Numeric representation of the month in two digits 01 (for January) through 12 (for December) Year : %C - Numeric representation of the century in two digits %g - Two digit representation of the year going by ISO-8601:1988 standards %G - The full four-digit representation of the year %y - Numeric representation of the year in two digits (Example: 99 for1999) %Y - Four digit representation for the year Example: 2011 Time : %H - 24-hour format of an hour (00 through 23) %I - 12-hour format of an hour (01 through 12 ) %l - 12-hour format of an hour without leading zeros (1 to 12) %M -Minutes with leading zeros (00 through 59) %p - UPPER-CASE 'AM' or 'PM' %P - lower-case 'am' or 'pm' %r - Same as "%I:%M:%S %p" %R - Same as "%H:%M" %S - Seconds with leading zero (00 through 59) %T - Same as "%H:%M:%S" %X - Represent times without the date %z - The time zone offset from UTC or the abbreviation %Z - The time zone offset or abbreviation if option NOT given by %z Time and Date Stamps : %c - A specific date and time stamp based on local %D - Same as "%m/%d/%y" %F - Same as "%Y-%m-%d" (usually used in database datestamps) %s - Unix Epoch Time timestamp %x - A date representation based on locale date, without the time Miscellaneous : %n - A newline character ("\n") %t - A Tab character ("\t") %% - A literal percentage character ("%") |
optional | string |
timestamp | An integer indicates the unixtimestamp. If a timestamp is not supplied, it gives the current local time. | optional | integer |
Return value
A formatted string.
Value Type: String.
Example:
<?php
echo(strftime("%B %D %Y %X", mktime(10,0,0,11,21,2004))."<br />");
echo(strftime("%b %d %Y %X", mktime(20,0,0,12,31,98))."<br />");
echo(strftime("Today is %a on %b %d, %Y, %X time zone: %Z",time()));
?>
Sample Output:
November 2004 10:00:00 Dec 31 1998 20:00:00 Today is Wed on Jan 19, 2011, 06:02:31 time zone: India Standard Time
View the example in the browser
See also
PHP: Tips of the Day
How to Sort Multi-dimensional Array by Value?
Try a usort, If you are still on PHP 5.2 or earlier, you'll have to define a sorting function first:
Example:
function sortByOrder($a, $b) { return $a['order'] - $b['order']; } usort($myArray, 'sortByOrder');
Starting in PHP 5.3, you can use an anonymous function:
usort($myArray, function($a, $b) { return $a['order'] - $b['order']; });
And finally with PHP 7 you can use the spaceship operator:
usort($myArray, function($a, $b) { return $a['order'] <=> $b['order']; });
To extend this to multi-dimensional sorting, reference the second/third sorting elements if the first is zero - best explained below. You can also use this for sorting on sub-elements.
usort($myArray, function($a, $b) { $retval = $a['order'] <=> $b['order']; if ($retval == 0) { $retval = $a['suborder'] <=> $b['suborder']; if ($retval == 0) { $retval = $a['details']['subsuborder'] <=> $b['details']['subsuborder']; } } return $retval; });
If you need to retain key associations, use uasort() - see comparison of array sorting functions in the manual
Ref : https://bit.ly/3i77vCC
- New Content published on w3resource:
- HTML-CSS Practical: Exercises, Practice, Solution
- Java Regular Expression: Exercises, Practice, Solution
- Scala Programming Exercises, Practice, Solution
- Python Itertools exercises
- Python Numpy exercises
- Python GeoPy Package exercises
- Python Pandas exercises
- Python nltk exercises
- Python BeautifulSoup exercises
- Form Template
- Composer - PHP Package Manager
- PHPUnit - PHP Testing
- Laravel - PHP Framework
- Angular - JavaScript Framework
- Vue - JavaScript Framework
- Jest - JavaScript Testing Framework