javascript get the number of milliseconds of a time

In JavaScript some time to get the number of milliseconds can use the built-in Date object easily achieved.

var time = new Date('2019-11-11').getTime(); // 1573430400000

To convert the number of milliseconds the time is also very simple.

new Date(1573430400000).Format('yyyy-MM-dd'); // 2019-11-11

I know the basics of points and then you can do a lot of advanced operations, such as the calculation of time difference between two dates.

was time1 = new Date ( '2019-11-11' ) .getTime ();
was TIME2 = new Date ( '2019-11-12' ) .getTime ();
was timeDiff = hour1 - hour1; // 86400000

Through the above calculation, we can know the time of day the number of milliseconds difference is 86400000, then we can use this to get the number of how many days of the date apart.

var time1 = new Date('2019-11-11').getTime();
var time2 = time1 + 86400000;
var nextDate = new Date(time2).Format('yyyy-MM-dd'); // 2019-11-12

So advanced operations are step by step through a stack-based operating together, the foundation is very important.

 

"Youth is not a train back."

Guess you like

Origin www.cnblogs.com/yanggb/p/11842852.html