-
- echo strtotime(”2009-1-22″) Result: 1232553600
-
Copy code
Description: Return the timestamp of 0:00:00 on January 22, 2009
Second, PHP timestamp function to obtain English text date and time
Examples are as follows:
For easy comparison, use date to convert the current timestamp and the specified timestamp into system time
(1) Print the timestamp at this time tomorrow strtotime(”+1 day”)
-
- Current time: echo date(”Y-m-d H:i:s”,time()) Result: 2009-01-22 09:40:25
- Specified time: echo date(”Y-m-d H:i: s",strtotime("+1 day")) Result: 2009-01-23 09:40:25
Copy code
(2) Print the timestamp of yesterday at this time strtotime("-1 day")
-
- Current time: echo date(”Y-m-d H:i:s”,time()) Result: 2009-01-22 09:40:25
- Specified time: echo date(”Y-m-d H:i: s”,strtotime(”-1 day”)) Result: 2009-01-21 09:40:25
Copy code
(3) Print the timestamp at this time next week strtotime(”+1 week ”)
-
- Current time: echo date(”Y-m-d H:i:s”,time()) Result: 2009-01-22 09:40:25
- Specified time: echo date(”Y-m-d H:i: s”,strtotime(”+1 week”)) Result: 2009-01-29 09:40:25
Copy code
(4) Print the timestamp at this time last week strtotime(”-1 week ”)
-
- Current time: echo date(”Y-m-d H:i:s”,time()) Result: 2009-01-22 09:40:25
- Specified time: echo date(”Y-m-d H:i: s”,strtotime(”-1 week”)) Result: 2009-01-15 09:40:25
Copy code
(5) Print the timestamp of the specified next day of the week strtotime(”next Thursday”)
-
- Current time: echo date(”Y-m-d H:i:s”,time()) Result: 2009-01-22 09:40:25
- Specified time: echo date(”Y-m-d H:i: s",strtotime("next Thursday")) Result: 2009-01-29 00:00:00
Copy code
(6) Print the timestamp of the specified day of the week strtotime("last Thursday")
-
- Current time: echo date(”Y-m-d H:i:s”,time()) Result: 2009-01-22 09:40:25
- Specified time: echo date(”Y-m-d H:i: s”,strtotime(”last Thursday”)) Result: 2009-01-15 00:00:00
-
Copy code
As can be seen from the above PHP timestamp function example, strtotime can describe the date and time of any English text To parse it into a Unix timestamp, we use mktime() or date() to format the date and time to obtain the specified timestamp and achieve the required date and time.
Example:
-
- //Convert timestamp to date
- $date_time_array = getdate(1297845628); //1311177600 1316865566
- $hours = $date_time_array["hours"];
- $minutes = $ date_time_array[" minutes"];
- $seconds = $date_time_array["seconds"];
- $month = $date_time_array["mon"];
- $day = $date_time_array["mday"];
- $year = $date_time_array["year" ];
-
- echo "year:$yearnmonth:$monthnday:$daynhour:$hoursnminutes:$minutesnseconds:$secondsn";
-
- //Convert normal date to timestamp
- echo mktime(0, 0, 0, 9, 18, 2011) . "n";
- echo mktime(0, 0, 0, 9, 25, 2011) . "n";
-
- /*
- time();
- is to get the current time, but it is an integer
- */
- //You can format this
- echo "time() displays year, month, day, hour, minute and second:" . date("Y-m-d H:i:s", time()) . "n";
- // In this way, the hours, minutes and seconds are displayed together
- echo "time() only displays the year, month and day:" . date("Y-m-d ", time()) . "n"; //Only the year is displayed.
- echo "Timestamp Formatting: " . date("Y-m-d H:i:s", 1297845628) . "n"; //Use timestamp directly
- /* vim: set ts=4 sw=4 sts=4 tw=100 noet: * /
- ?>
Copy code
Articles you may be interested in:
A summary of how to obtain the current time and timestamp in php
php timestamp function strtotime application example
php timestamp application example
php time conversion Unix timestamp code
Learn how to convert timestamp and date formats in php
|