search
HomeBackend DevelopmentPHP Tutorial 一些时间比较及转换的有关问题

一些时间比较及转换的问题
需求输入两个时间,只需要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("正确");
}
}



还有一个问题是,我的数据库里有一个字段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、
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中 
Statement
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
alert怎么实现换行alert怎么实现换行Nov 07, 2023 am 10:19 AM

alert通过使用br标签来实现换行。

php提交表单通过后,弹出的对话框怎样在当前页弹出,该如何解决php提交表单通过后,弹出的对话框怎样在当前页弹出,该如何解决Jun 13, 2016 am 10:23 AM

php提交表单通过后,弹出的对话框怎样在当前页弹出php提交表单通过后,弹出的对话框怎样在当前页弹出而不是在空白页弹出?想实现这样的效果:而不是空白页弹出:------解决方案--------------------如果你的验证用PHP在后端,那么就用Ajax;仅供参考:HTML code<form name="myform"

getElementById怎么用getElementById怎么用Sep 01, 2023 am 11:03 AM

getElementById可以通过元素的id属性获取对应的HTML元素,进而方便地对其进行操作和修改。无论是动态地改变元素的内容、样式或者是添加事件监听器,getElementById都是一个非常常用的方法 。

javascript中alert乱码怎么办javascript中alert乱码怎么办Feb 10, 2023 am 09:40 AM

javascript中alert乱码的解决办法:1、在html中<head>部分加入“charset=utf-8"”;2、在<script>标签中加入“charset="gb2312"”或者“charset="utf-8"”;3、更改js外部脚本的保存编码为utf8即可。

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

不用数据库来实现用户的简单的下载,代码如下,但是却不能下载,请高手找下原因,文件路劲什么的没问题。<?phpfunction down_file($file_name,$file_sub_dir){//为防止乱码使用函数iconv$file_name=iconv("utf-8","gb2312",$file_

为什么小弟我在php上写的这个代码,在浏览器上什么都不显示为什么小弟我在php上写的这个代码,在浏览器上什么都不显示Jun 13, 2016 am 10:24 AM

为什么我在php上写的这个代码,在浏览器上什么都不显示啊<?php   if(isset($_POST['Submit'])&& $_POST['Submit']=="登陆"){   $user=$_POST['user']; $pass=$_POST['pass']; if(empt

图片消失怎么解决图片消失怎么解决Apr 07, 2024 pm 03:02 PM

图片消失如何解决先是图片文件上传$file=$_FILES['userfile'];  if(is_uploaded_file($file['tmp_name'])){$query=mysql_query("INSERT INTO gdb_banner(image_src ) VALUES ('images/{$file['name'

图片消失怎么解决图片消失怎么解决Jun 13, 2016 am 10:09 AM

图片消失如何解决先是图片文件上传$file=$_FILES['userfile'];  if(is_uploaded_file($file['tmp_name'])){$query=mysql_query("INSERT INTO gdb_banner(image_src ) VALUES ('images/{$file['name'

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.