Home > Web Front-end > JS Tutorial > body text

js implementation code for finding time difference_javascript skills

WBOY
Release: 2016-05-16 15:03:53
Original
1599 people have browsed it

var date1=new Date(); //Start time
var date2=new Date(); //End time
var date3=date2.getTime()-date1.getTime() //The number of milliseconds of the time difference

//Calculate the number of days difference
var days=Math.floor(date3/(24*3600*1000))
//Calculate the number of hours

var leave1=date3%(24*3600*1000) //The number of milliseconds remaining after calculating the number of days
var hours=Math.floor(leave1/(3600*1000))

//Calculate the difference in minutes
var leave2=leave1%(3600*1000) //The number of milliseconds remaining after calculating the number of hours
var minutes=Math.floor(leave2/(60*1000))
//Calculate the difference in seconds
var leave3=leave2%(60*1000) //The number of milliseconds remaining after calculating the minutes
var seconds=Math.round(leave3/1000)

alert(" Difference "+days+"Days "+hours+" Hours "+minutes+" Minutes"+seconds+" Seconds")

Math.floor(Math.abs(k1 - k2) / 1000 / 60 / 60 /24 + 0.5);//Time difference rounding

document.write("Two decimal points:"+a.toFixed(2)+"
Four decimal points"+a.toFixed(4));

The above JS time difference implementation code is all the content shared by the editor. I hope it can give you a reference, and I hope you will support Script Home.

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template