How to convert time format in php: You can use date function to convert time format, such as [$y=date("Y",time()); $m=date("m",time() ); $d=date("d",time());】.
The method is as follows:
(Recommended tutorial:php video tutorial)
1. Complete the conversion in MySQL
in the MySQL query statement. The advantage is that it does not take up the parsing time of the PHP parser and is fast. The disadvantage is that it can only be used in database queries and has limitations.
1. Use the function to convert UNIX timestamp to date: FROM_UNIXTIME()
2. Use the function to convert date to UNIX timestamp: UNIX_TIMESTAMP()
2. Complete the conversion in PHP
Complete the conversion in the PHP program. The advantage is that it can be converted regardless of whether the data is obtained by querying in the database. The conversion range is not limited. The disadvantage is that it takes up PHP parsing. The parsing time of the processor is relatively slow
1. Use the function to convert UNIX timestamp to date: date()
2. Use the function to convert date to UNIX timestamp: strtotime()
$y=date("Y",time()); //年 $m=date("m",time()); //月 $d=date("d",time()); //日 echo $y."
"; echo $m."
"; echo $d."
"; $eight_clock = mktime(8, 0, 0, $m, $d ,$y); //每天8点 echo date("Y-m-d H:i:s",$eight_clock)."
"; $day_time = mktime(0, 0, 0, $m, 1 ,$y); //每月1号 echo date("Y-m-d H:i:s",$day_time)."
";
Related recommendations:php training
The above is the detailed content of How to convert time format in php. For more information, please follow other related articles on the PHP Chinese website!