PHP+MYSQL怎麼儲存和讀取格式化時間。

來源:互聯網
上載者:User
註:只需要儲存、讀取和判斷時間,不包括日期。。

開始時間:08:30:00
結束時間:18:00:00
在表單中輸入如上格式的時間,可否用int類型儲存到MYSQL資料庫,又怎麼用PHP讀取列印出來?
並且可以判斷伺服器目前時間是否處於開始和結束之間。


回複討論(解決方案)

存資料庫之前,用strtotime轉成10位元字, 然後判斷直接比就好了。

可以直接存字串,與目前時間也可以進行比較。

儲存和讀取解決了,,請問怎麼判斷?能具體一點嗎?

你怎麼儲存的和讀取的,最好貼出代碼以供分析。

存:
$_POST['time1']='08:00:08';
$_POST['time2']='16:00:08';
$data['time1']=strtotime(in($_POST['time']));
$data['time2']=strtotime(in($_POST['time']));
讀:
$info['time1']=1395100808;
$info['time2']=1395129608;
$time1=date("H:i:s",$info['time1']);
$time2=date("H:i:s",$info['time2']);

求怎麼判斷當前伺服器時間是否為:
$time1
$time2
之間。

$current = date("H:i:s");if( $current >$time1 && $current < $time2){     echo '之間';}else{     echo '非之間';}

$current = date("H:i:s");if( $current >$time1 && $current < $time2){     echo '之間';}else{     echo '非之間';}


我一般用此方法 date("H:i:s") 這樣輸出來的結果就是樓主所要的結果
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.