php時間格式處理方法

來源:互聯網
上載者:User
1. 把‘2016-06-16’格式轉換成‘20160616’


<?php
header("Content-type: text/html; charset=utf-8");
$txDate = '2016-06-16';
$dateTime = explode('-', $txDate);
$Time = $dateTime[0].$dateTime[1].$dateTime[2];
var_dump($Time);

結果:string '20160616' (length=8)
?>

$dateTime = explode('-', $params['txDate']);
$dateTime = $dateTime['0'].$dateTime['1'].$dateTime['2'];   var_dump($dateTime); //20160616

2. 按日期 YYYY-MM-DD 格式 “2016-06-16 00:00:00” 查詢今日內容。需拼接今日起始時間。


<?phpheader("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);

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.