Definition and Usage
The date () function formats a local time/date.
Syntaxdate (Format,timestamp)
Parameterdescriptionformat Required. Specifies how to return the result:
- D-the Day of the month (from 31)
- D-a Textual representation of A Day (three letters)
- J-the Day of the month without leading zeros (1 to 31)
- L (lowercase ' l ')-a full textual representation of a day
- N-the ISO-8601 numeric representation of a day (1 for Monday through 7 for Sunday)
- S-the 中文版 ordinal suffix for the day of the month (2 characters St, ND, RD or th. Works well with J)
- W-a numeric representation of the day (0 for Sunday through 6 for Saturday)
- Z-the Day's (from 0 through 365)
- W-the ISO-8601 Week number of year (weeks starting on Monday)
- F-a full textual representation of A month (January through December)
- M-a numeric representation of A month (from 12)
- M-a short textual representation of A month (three letters)
- N-a numeric representation of A month, without leading zeros (1 to 12)
- T-the number of days in the given month
- L-whether It's a leap year (1 if it's a leap year, 0 otherwise)
- O-the ISO-8601 Year Number
- Y-a four digit representation of A year
- Y-a digit representation of A year
- A-lowercase am or PM
- A-uppercase AM or PM
- B-swatch Internet Time (999)
- G-12-hour format of an hour (1 to 12)
- G-24-hour format of an hour (0 to 23)
- H-12-hour format of an hour (12)
- H-24-hour format of an hour (xx to 23)
- I-minutes with leading zeros (xx to 59)
- S-seconds, with leading zeros (xx to 59)
- E-the timezone identifier (EXAMPLES:UTC, atlantic/azores)
- I (capital i)-Whether the date was in Daylights savings time (1 if Daylight savings time, 0 otherwise)
- O-difference to Greenwich time (GMT) in hours (Example: +0100)
- T-timezone setting of the PHP machine (examples:est, MDT)
- Z-timezone offset in seconds. The offset west of UTC is negative, and the offset east of UTC was positive ( -43200 to 43200)
- C-the ISO-8601 date (e.g. 2004-02-12t15:19:21+00:00)
- R-the RFC 2822 formatted date (e.g. Thu, DEC 2000 16:01:07 +0200)
- U-the seconds since the Unix Epoch (January 1 1970 00:00:00 GMT)
Timestampoptional.
Example
function Ttodatetime ($text) {
$myDatetimeStr =date (' Y ', Strtotime ($text)). " -". Date (' m ', Strtotime ($text)). " -". Date (' d ', Strtotime ($text)). " ". Date (' H ', Strtotime ($text)). ":". Date (' I ', Strtotime ($text)). ":". Date (' s ', Strtotime ($text));
return $myDatetimeStr;
}
Echo $text;
echo Ttodatetime ($text);
Result
"01/07/2012 13:44", 2012-01-07 13:44:00
Format and Ttodatetime functions for datetime in PHP