1const date1 = new Date('7/13/2010');
2const date2 = new Date('12/15/2010');
3console.log(getDifferenceInDays(date1, date2));
4console.log(getDifferenceInHours(date1, date2));
5console.log(getDifferenceInMinutes(date1, date2));
6console.log(getDifferenceInSeconds(date1, date2));
7
8function getDifferenceInDays(date1, date2) {
9 const diffInMs = Math.abs(date2 - date1);
10 return diffInMs / (1000 * 60 * 60 * 24);
11}
12
13function getDifferenceInHours(date1, date2) {
14 const diffInMs = Math.abs(date2 - date1);
15 return diffInMs / (1000 * 60 * 60);
16}
17
18function getDifferenceInMinutes(date1, date2) {
19 const diffInMs = Math.abs(date2 - date1);
20 return diffInMs / (1000 * 60);
21}
22
23function getDifferenceInSeconds(date1, date2) {
24 const diffInMs = Math.abs(date2 - date1);
25 return diffInMs / 1000;
26}
1var secondBetweenTwoDate = Math.abs((new Date().getTime() - oldDate.getTime()) / 1000);
1var t1 = new Date();
2var t2 = new Date();
3var dif = t1.getTime() - t2.getTime();
1var t1 = new Date(YYYY, MM, DD, 0, 0, 0, 0);
2var t2 = new Date(ZZZZ, NN, EE, 0, 0, 0, 0);
3var dif = t1.getTime() - t2.getTime();
4
5var Seconds_from_T1_to_T2 = dif / 1000;
6var Seconds_Between_Dates = Math.abs(Seconds_from_T1_to_T2);