PHP+MYSQL怎么存储和读取格式化时间。

WBOY
Release: 2016-06-23 14:00:28
Original
1062 people have browsed it

注:只需要存储、读取和判断时间,不包括日期。。

开始时间: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 '非之间';}
Copy after login
Copy after login

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


我一般用此方法  date("H:i:s") 这样输出来的结果就是楼主所要的结果

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!