辛苦的字幕君小样 2013-05-16
<?php
date_default_timezone_set("prc");//将时区设置为中国
$stringtime = date("Y-m-d H:i:s",time());
echo $stringtime."<br/>";
echo strtotime($stringtime)."<br/>";
echo date("Y/m/d G:i:s A",strtotime($stringtime));
echo "<br><br><br><br>";
$stringtime2 = "2013-05-16 09:31:56";//自己设置,目的是比较2个时间的差
echo $stringtime2."<br/>";
echo strtotime($stringtime2)."<br/>";
echo date("Y/m/d G:i:s A",strtotime($stringtime2));
echo "<br><br><br><br>";
echo strtotime($stringtime2) - strtotime($stringtime);
?>说明:
date_default_timezone_set("");设置时区,php5.1以上,time()获得的时间比实际时间慢了8个小时。所以要设置时区。也可以使用date_default_timezone_set('Etc/GMT-8');设置时区
详情参考:http://www.php.net/manual/en/timezones.php
如果要将时间戳保存到数据库里,我使用的是varchar类型
<?php. if (!empty($_POST)) {. $data1 = $_POST["data1"];$data2 = $_POST["data2"];$fuhao = $_POST["fuh