1. 把‘2016-06-16’格式转换成‘20160616’
<span style="color: #0000ff"></span><span style="color: #0000ff"><?php<br/>header("Content-type: text/html; charset=utf-8"); <br/>$txDate = '2016-06-16';<br/>$dateTime = explode('-', $txDate);<br/>$Time = $dateTime[0].$dateTime[1].$dateTime[2];<br/>var_dump($Time);<br/><br/>结果:string '20160616' (length=8) <br/>?><br/><br/> $dateTime = explode('-', $params['txDate']);<br/> $dateTime = $dateTime['0'].$dateTime['1'].$dateTime['2']; var_dump($dateTime); //20160616<br/></span>
2. 按日期 YYYY-MM-DD 格式 “2016-06-16 00:00:00” 查询今日内容。需拼接今日起始时间。
<?php header("Content-type: text/html; charset=utf-8"); $txDate = '2016-06-16'; $dateTime1 = strtotime($txDate); //int 1466028000 将英文文本日期时间解析为 Unix 时间戳: $dateTime2= date("Y-m-d H:i:s",$dateTime1); //string '2016-06-16 00:00:00' (length=19) Date() 函数把时间戳格式化为更易读的日期和时间。 //拼接今日最后时间2016-06-16 23:59:59 $dateTime= date("Y-m-d H:i:s",strtotime(date("Y-m-d",strtotime($dateTime2))."+ 23 hours 59 minutes 59 seconds ")); //string '2016-06-16 23:59:59' (length=19) $sql = select * form `vvt_user` where userid = 100 AND date_time >= $dateTime2 AND date_time <= $dateTime; ?>
3. php中查询sql 把时间转换成unix时间戳进行比较;
$sql .= ' AND UNIX_TIMESTAMP(vvt_repayment.date) >= '.strtotime($day); $sql .= ' AND UNIX_TIMESTAMP(vvt_repayment.date) <= '.strtotime($endday);
以上是php时间格式处理方法的详细内容。更多信息请关注PHP中文网其他相关文章!