php时间戳与字符串的相互转换
<?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类型
相关推荐
MXstudying 2020-09-05
WasteLand 2020-09-15
<?php. if (!empty($_POST)) {. $data1 = $_POST["data1"];$data2 = $_POST["data2"];$fuhao = $_POST["fuh
mathchao 2020-09-15
zyyjay 2020-11-09
xuebingnan 2020-11-05
samtrue 2020-11-22
stefan0 2020-11-22
yifangs 2020-10-13
songshijiazuaa 2020-09-24
hebiwtc 2020-09-18
天步 2020-09-17
83911535 2020-11-13
whatsyourname 2020-11-13
zhouyuqi 2020-11-10
Noneyes 2020-11-10
mathchao 2020-10-28
王志龙 2020-10-28