首页 > 开发 > PHP > 正文

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

2024-05-04 22:54:59
字体:
来源:转载
供稿:网友


<?
$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>";
?>

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表