//输出时间戳 ehco time(); //1590937860 //输出日期 echo date('Y-m-d'); //2020-05-31 echo date('Y-m-d H:i:s'); //2020-05-31 23:11:00 ... //时间戳转化为日期和时间 $date=date('Y-m-d',"1285724523"); echo $date."<br />\r\n"; --2010-09-29 ... //时间戳转化为时间 $date=date('Y-m-d H:i:s',"1285724523"); echo $date."<br />\r\n"; --2010-09-29 09:42:03 ... //将日期转化为时间戳 $date=date('Y-m-d',"1285724523"); $temp=explode("-",$date); echo "--".$temp[0]."|".$temp[1]."|".$temp[2]."<br />\r\n"; //--2010|09|29 echo mktime(0,0,0,$temp[1],$temp[2],$temp[0])."<br />\r\n"; //1285689600 echo "--".mktime(0,0,0,9,29,2010)."<br />\r\n"; //--1285689600 ... //将时间转化为时间戳 $date=date('Y-m-d H:i:s',"1285724523"); echo $date."<br>"; //2010-09-29 09:42:03 $temp=explode(" ",$date); $temp1=explode("-",$temp[0]); $temp2=explode(":",$temp[1]); echo mktime($temp2[0],$temp2[1],$temp2[2],$temp1[1],$temp1[2],$temp1[0])."<br />\r\n"; //1285724523 echo $temp2[0]."|".$temp2[1]."|".$temp2[2]."|".$temp1[1]."|".$temp1[2]."|".$temp1[0]."<br />\r\n"; //-->09|42|03|09|29|2010 echo mktime(9,42,3,"09","29","2010")."<br />\r\n"; //1285724523 echo mktime(9,42,3,09,29,2010)."<br />\r\n"; //这样报错:年月日必须有引号 ... //示例: $temp=explode(" ","2009-07-28 22:34:41"); $temp1=explode("-",$temp[0]); $temp2=explode(":",$temp[1]); echo mktime($temp2[0],$temp2[1],$temp2[2],$temp1[1],$temp1[2],$temp1[0])."<br />\r\n"; //1248791681 $atime=mktime($temp2[0],$temp2[1],$temp2[2],$temp1[1],$temp1[2],$temp1[0])."<br />\r\n"; //var_dump($atime)."<br />\r\n"; // string(18)"1248791681" echo $atime; //1248791681 echo date("Y-M-D h:i:s",$atime)."<br />\r\n"; //2009-Jul-Tue 10:34:41 echo date("Y-m-d h:i:s",$atime)."<br />\r\n"; //2009-07-28 10:34:41 echo date("y-m-d h:i:s",$atime)."<br />\r\n"; //09-07-28 10:34:41 echo date("Y-m-d H:i:s",$atime)."<br />\r\n"; //2009-07-28 22:34:41
完美原创,转载请注明原文链接!
Tag: PHP 时间戳 日期时间