萬盛學電腦網

 萬盛學電腦網 >> 網絡編程 >> php編程 >> 例子:把字符串時間轉換為timestamp

例子:把字符串時間轉換為timestamp

$strtime = "2000-02-12 16:20:35";
$array = explode("-",$strtime);
$year = $array[0];
$month = $array[1];
$array = explode(":",$array[2]);
$minute = $array[1];
$second = $array[2];
$array = explode(" ",$array[0]);
$day = $array[0];
$hour = $array[1];
$timestamp = mktime($hour,$minute,$second,$month,$day,$year);
echo "字符串時間:$strtime<br>";
echo "年:$year<br>";
echo "月:$month<br>";
echo "日:$day<br>";
echo "時:$hour<br>";
echo "分:$minute<br>";
echo "秒:$second<br>";
echo "轉換為timestamp:" . $timestamp . "<br>";
echo "從timestamp轉換回來:" . date("Y-m-d H:i:s",$timestamp) . "<br>";
?>

copyright © 萬盛學電腦網 all rights reserved