Home>

In order to achieve such a function today-users can manually enter the date,But dates can only be entered before today,Cannot submit after today,That is today is the 15th, you can only enter the date before the 15th,Dates after the 15th cannot be entered

/**
 Convert string to yyyymmdd format to date type
 date is the date string
* /
function getdate (date) {
 var year=date.substr (0,4);//substr () is calculated from 0
 var month=date.substr (4,2);//month is 0 to 11 months
 var day=date.substr (6,2);
 alert (year + "-" + month + "-" + day);
 return new date (year, month, day);
}
var date=getdate ("20120704");
var date2=getdate ("20120720");
//alert (date.gettime ());
//alert (date2.gettime ());
alert (date2.gettime ()-date.gettime ())

The second method (including hours, minutes and seconds)

var d1=new date ("2004/09/16 20:08:00");
var d2=new date ("2004/09/16 10:18:03");
//Get the time difference between the two
var d3=d1-d2;
//alert (d1.gettime ());
//alert (d2.gettime ());
//The result of the pop-up message below is the same
alert (d3);
alert (d1.gettime ()-d2.gettime ());

The third way (may not include hours, minutes and seconds)

var d1=new date ("2004/09/17");
var d2=new date ("2004/09/16");
//Get the time difference between the two
var d3=d1-d2;
//alert (d1.gettime ());
//alert (d2.gettime ());
//The result of the pop-up message below is the same
alert (d3);
alert (d1.gettime ()-d2.gettime ());

ps:Here is an online timestamp conversion tool.It contains a description of the timestamp operation method tables of various common programming languages ​​such as javascript, php, java, python, c#,I believe that in the future programming development you will use:

  • Previous Search method using jquery in iframe [Case Study]
  • Next JS simply implements the method of DIV relative to the fixed position of the browser