一些时间比较及转换的有关问题
Jun 13, 2016 pm 01:14 PM
alert
getelementbyid
quot
一些时间比较及转换的问题
需求输入两个时间,只需要HH:MM 即小时和分钟
我是用 进行输入
例如输入 11:30 12:30 那么如何将这两个转换为时间格式做比较呢?百度了一堆都是天与天之间比较的
下面是我模仿着写的JS,转换时间那里肯定是有问题的,要如何改写呢?
- JScript code
<!-- Code highlighting produced by Actipro CodeHighlighter (freeware) http://www.CodeHighlighter.com/ -->function comparetime(){ var starttime = document.getElementById("starttime").value; var stoptime = document.getElementById("stoptime").value; var time1=(starttime).toTimeString(); //应该是这里处理的方法有问题 var time2=(stoptime).toTimeString(); if(starttime > stoptime){ alert("输入的时间有误"); } else { alert("正确"); } }
Copy after login
还有一个问题是,我的数据库里有一个字段searchtime 字段类型为datetime,
我通过PHP页面对这个表进行update的操作,我想谁设定在这个searchtime+12小时之后,就不能通过PHP
页面进行update操作了 我知道加个判断就可以了,通过$searchtime=$row['$searchtime'] 获取时间也没问题,就是不知道
$searchtime如何加这12个小时,也是时间格式转换的问题
------解决方案--------------------
可以这么写
- JScript code
function comparetime(){ var starttime = document.getElementById("starttime").value; var stoptime = document.getElementById("stoptime").value; var t1=starttime.split(':'); var t2=stoptime.split(':'); var time1=new Date(75, 1, 16, t1[0], t1[1], 0); var time2=new Date(75, 1, 16, t2[0], t2[1], 0); if(starttime > stoptime){ alert("输入的时间有误"); } else { alert("正确"); } } <br><font color="#e78608">------解决方案--------------------</font><br>1、
Copy after login
- JScript code
s1 = '11:30'; s2 = '12:30'; d = new Date(); t = s1.split(/:/); d.setHours(t[0], t[1]); t1 = d.getTime(); t = s2.split(/:/); d.setHours(t[0], t[1]); t2 = d.getTime(); if(t1 > t2) alert('ok'); else alert('error'); <br><font color="#e78608">------解决方案--------------------</font><br>duibi 方法就不要alert了,直接返回false或 true就行了<br><br>if(starttimes >= stoptimes){<br> alert("输入时间有误");<br> return false;<br>}<br>else {<br> return true;<br>}<br>function setSubmit(){<br> ...............这里验证ACE_HIDDEN_TABLE 下的两个input 框.................<br> var inputs=document.getElementById('newTB').getElementsByTagName('input');<br><br> for(var i=0;i<inputs.length></inputs.length> if(!duibi(inputs[i].value,inputs[i+1].value)){<br> alert('输入有误');<br> return false;<br> }<br> }<br> return true;<br>}<br><br>然后在你的form中
Copy after login
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

Hot Article
Repo: How To Revive Teammates
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
How Long Does It Take To Beat Split Fiction?
3 weeks ago
By DDD
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌

Hot tools Tags

Hot Article
Repo: How To Revive Teammates
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
How Long Does It Take To Beat Split Fiction?
3 weeks ago
By DDD
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

What to do if alert is garbled in javascript

不用数据库来实现用户的简单的下载,代码如下,但是却不能下载,请高手找下原因,文件路劲什么的没有关问题
