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

WBOY
Release: 2016-06-01 12:40:50
Original
928 people have browsed it

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

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!