How to convert php time to timestamp: First create a PHP sample file; then use the strtotime function to convert the date represented by the text string into a timestamp, or use the mktime function to obtain the timestamp from the date.
The operating environment of this tutorial: Windows 7 system, PHP version 5.6. This method is suitable for all brands of computers.
Recommended: "PHP Video Tutorial"
PHP date format and timestamp conversion
Date conversion to unix timestamp
1. The strtotime() function is used to convert the date represented by the English text string into a timestamp. It is the inverse function of date(). It returns the timestamp successfully, otherwise it returns FALSE
echo strtotime("2009-10-21 16:00:10"); //输出 1256112010 echo strtotime("10 September 2008"); //输出 1220976000 echo strtotime("+1 day"), "<br />"; //输出明天此时的时间戳
Print the timestamp at this time yesterday strtotime("-1 day")
Print the timestamp at this time next week strtotime(" 1 week")
Print the timestamp at this time last week Timestamp strtotime("-1 week")
Get the timestamp of zero o'clock today. To get the unix timestamp of zero o'clock, you can use
$todaytime=strtotime(“today”),
2, mktime()
The mktime() function is used to obtain a timestamp from a date and returns the timestamp successfully, otherwise it returns FALSE. Syntax:
int mktime(hour, minute, second, month, day, year)
Example:
<?php echo mktime(21, 50, 55, 07, 14, 2010); //输出“1279115455” ?>
Convert unix timestamp to date
date("Y-m-d H:i:s",time()), "Y-m-d H:i:s" is the converted date format, and time() is the timestamp to obtain the current time. If it is date("Y-m-d H:i:s", time()), the hours, minutes and seconds will be displayed together; if it is
date("Y-m-d ", time()), only the year, month and day will be displayed
The above is the detailed content of How to convert php time to timestamp. For more information, please follow other related articles on the PHP Chinese website!