1 window.onload = function(){ 2 3 function dwn(s){ 4 document.write(s+"<br />"); 5 } 6 7 var date = new Date(); 8 9 dwn(date); 10 dwn(date.toString()); 11 dwn(date.toLocaleString()); 12 dwn(date.valueOf()); //显示毫秒数 13 dwn(date.toDateString()); 14 dwn(date.toTimeString()); 15 dwn(date.toLocaleDateString()); 16 dwn(date.toLocaleTimeString()); 17 dwn(date.toUTCString()); 18 19 dwn(date.getFullYear()+"-"+(date.getMonth()+1)+"-"+date.getDate()); 20 dwn("星期"+date.getDay()); 21 dwn(date.getHours()+":"+date.getMinutes()+":"+date.getSeconds()+":"+date.getMilliseconds()); 22 23 24 function f1(){ 25 26 return function(){ //闭包是可以访问函数作用域里变量的函数 27 return "这是一个闭包"; 28 } 29 30 } 31 32 }
结果:
Mon Jan 05 2015 10:02:46 GMT+0800
Mon Jan 05 2015 10:02:46 GMT+0800
2015/1/5 上午10:02:46
1420423366509
Mon Jan 05 2015
10:02:46 GMT+0800
2015/1/5
上午10:02:46
Mon, 05 Jan 2015 02:02:46 GMT
2015-1-5
星期1
10:2:46:509
时间: 2024-11-05 20:33:15