日期:2014-05-18  浏览次数:20762 次

javascript中如何比较两个字符串形式的时间之间的分差
我的源代码如下:
<script   language= "javascript ">
var   date1= "2001-01-01   10:10:00 ";
var   date2= "2002-02-02   12:12:00 ";
</script>

我想求两个字符串形式的时间之间相差多少分钟

------解决方案--------------------
<script language= "javascript ">
function a(){
var date1= "2001-01-01 10:10:00 ";
var date2= "2002-02-02 12:12:00 ";

var tmp1 = date1.split( " ");
var a1 = tmp1[0].split( "- ");
var a2 = tmp1[1].split( ": ");

var tmp2 = date2.split( " ");
var b1 = tmp2[0].split( "- ");
var b2 = tmp2[1].split( ": ");

var d1 = new Date(a1[0],a1[1]-1,a1[2],a2[0],a2[1],a2[2]);
var d2 = new Date(b1[0],b1[1]-1,b1[2],b2[0],b2[1],b2[2]);
var minutes = parseInt((d2 - d1) / 1000);
document.write(minutes );
}
</script>

<body>
<input type= "button " name= "button " onClick= "a() " value= "button ">
</body>