Javascript date subtraction, time difference, and javascript Time Difference
// Calculate the time difference
Var from_date = new Date (from_time );
Var end_date = new Date (end_time );
Var time_different = (end_date-from_date)/86400000; // that is, 24*60*60*1000 in milliseconds
/*
If (time _ different> 365 ){
Alert ('time span cannot exceed one year ');
}
*/
The difference between the current date and time in the javascript System and the date on which the database is obtained is reduced.
You can manually write the date subtraction.
Take out the year, month, and day, And subtract them accordingly. If not, use a bid. Just like decimal subtraction, there are some changes in the borrow space here.
By day and by month.
Javascript date subtraction involves time, minute, and second
If the date is in the string format, convert the string to the date, for example:
Var s1 = new Date ("00:58:30 ");
Var s2 = new Date ("08:58:48 ");
Then get the object's millisecond representation using getTime () Subtraction
Var s3 = s2.getTime ()-s1.getTime ();
Returns the number of milliseconds of difference.
Then, based on 1 day = 24 hours = (24*60) minutes = (24*60*60) seconds = (24*60*60*1000) milliseconds
Var tianshu = s3/(24x60*60*1000 );
In this way, the number of days is different.
All of them are manually typed. Thank you for your adoption.