首頁 >後端開發 >php教程 >例子:把字符串时间转换为timestamp_PHP

例子:把字符串时间转换为timestamp_PHP

WBOY
WBOY原創
2016-06-01 12:40:50961瀏覽

$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
";
echo "年:$year
";
echo "月:$month
";
echo "日:$day
";
echo "时:$hour
";
echo "分:$minute
";
echo "秒:$second
";
echo "转换为timestamp:" . $timestamp . "
";
echo "从timestamp转换回来:" . date("Y-m-d H:i:s",$timestamp) . "
";
?>

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn