Some time comparison and conversion problems

Source: Internet
Author: User
For some time comparison and conversion problems, you need to enter two time options: HH: MM, namely, hour and minute. & nbsp; I use & lt; inputtype = & quot; text & quot; name = & quot; starttime & quot;/& gt; & lt; inputtype = & quot; t time comparison and conversion problems
You need to enter two time periods: HH: MM, namely, hour and minute.
I use Input
For example, if you enter, how do you convert the two to the time format for comparison? Baidu has a bunch of comparisons between days.
Below is the js I have imitated. there must be a problem with the conversion time. how can I rewrite it?
JScript code
  Function comparetime () {var starttime = document. getElementById ("starttime "). value; var stoptime = document. getElementById ("stoptime "). value; var time1 = (starttime ). toTimeString (); // The method to be processed here is problematic var time2 = (stoptime ). toTimeString (); if (starttime> stoptime) {alert ("incorrect input time") ;}else {alert ("correct ");}}



Another problem is that the searchtime field in my database is of the datetime type,
I update this table on the PHP page. I wonder who will be unable to use PHP after this searchtime + 12 hours.
After the page is updated, I can add a judgment. it is okay to get the time through $ searchtime = $ row ['$ searchtime'], that is, I don't know.
$ How to add these 12 hours to searchtime is also a problem of time format conversion.

------ Solution --------------------
It can be written in this way.
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 ("incorrect input time ");} else {alert ("correct ");}}
------ Solution --------------------
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 ');
------ Solution --------------------
The duibi method does not need alert. simply return false or true.

If (starttimes> = stoptimes ){
Alert ("incorrect input time ");
Return false;
}
Else {
Return true;
}
Function setSubmit (){
.......... Here verify the two input boxes in ACE_HIDDEN_TABLE .................
Var inputs = document. getElementById ('newtb'). getElementsByTagName ('input ');

For (var I = 0; I
If (! Duibi (inputs [I]. value, inputs [I + 1]. value )){
Alert ('incorrect input ');
Return false;
}
}
Return true;
}

Then in your form

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.