汇总javascript中的时差

时间:2017-07-12 11:02:33

标签: javascript

我能够获得两个日期之间的时差,但是我无法将结果整理成2.163611111111111

var currentDate = new Date()
var day = currentDate.getDate()
var month = currentDate.getMonth() + 1
var year =  currentDate.getFullYear()
var hour =  currentDate.getHours();
var minute= currentDate.getMinutes(); 
var second= currentDate.getSeconds(); 

var today = day + "/" + month + "/" + year 
var time =  hour + ":" + minute + ":" + second 
console.log(today+' '+time);
var date1 = new Date('12/7/2017 01:51:14');
var date2 = new Date(today+' '+time);
var timeDiff = Math.abs(date2.getTime() - date1.getTime());
var hours = Math.abs(date2 - date1) / 36e5;
alert(hours)

这样我就可以将其整理成2.6

1 个答案:

答案 0 :(得分:0)

//in XML 
    <include layout="@layout/extLayout" 
    android:id="@+id/myLayout" />

//in Activity 
    View view= findViewById(R.id.myLayout);
    Button button= (TextView) view.findViewById(R.id.button);