- How to declare a time variable
- How to set time, minutes, seconds, and milliseconds for a temporal variable
- How to declare a specified time variable based on a string variable
- How to compare two time variables
The code is as follows:
1 $ (function () {2 varD =NewDate ();3D.sethours (0); D.setminutes (0); D.setseconds (0); D.setmilliseconds (0);4 5 varZhiding ="2015-08-10";6 if(zhiding.length===Ten){7zhiding+='00:00:00';8 }9 varD2 =NewDate (Zhiding.replace (/-/g,'/'));Ten if(d-d2==0) Alert ('The current time is equal to the specified time'); One Else if(d-d2>0) Alert ('The current time is greater than the specified time'); A Else if(d-d2<0) Alert ('The current time is less than the specified time'); -})
The first three points, a look at the show, about how to compare two time variables, but ate a great hardship, the previous code is the use of this notation, but not the correct results:
1 if (d = = D2) alert (' current time equals specified time '); 2 Else if (d > D2) alert (' current time is greater than specified time '); 3 Else if (d < D2) alert (' current time is less than the specified time ');
How to operate time in "draft" JS