function show(){
var date = new Date(); //日期对象
var now = "";
now = date.getFullYear()+"-"; //读英文就行了
now = now + (date.getMonth()+1)+"-";//取月的时候取的是当前月-1如果想取当前月+1就可以了
now = now + date.getDate()+" ";
now = now + date.getHours()+":";
now = now + date.getMinutes()+":";
now = now + date.getSeconds()+"";
document.getElementById("nowDiv").innerHTML = now; //div的html是now这个字符串
setTimeout("show()",1000); //设置过1000毫秒就是1秒,调用show方法
}
</script>
就是这段代码,比如说取出今天的时间是2007-8-10 12:40:1
我要的日期格式是 2007-08-10 12:40:01
这样比较
<script>
var d1="2009-8-1";
var d2="2009-7-15";
d1Arr=d1.split('-');
d2Arr=d2.split('-');
v1=new Date(d1Arr[0],d1Arr[1],d1Arr[2]);
v2=new Date(d2Arr[0],d2Arr[1],d2Arr[2]);
alert(v1>v2);
</script>