Date.prototype.format = function() { var s = ''; var mouth = (this.getMonth() + 1)>=10?(this.getMonth() + 1):('0'+(this.getMonth() + 1)); var day = this.getDate()>=10?this.getDate():('0'+this.getDate()); s += this.getFullYear() + '-'; // 获取年份. s +=
js中的Date类型是使用UTC(国际协调时间)自1970年1月1日午夜(零时)开始,经过的毫秒数来保存日期. 1. 创建日期对象 ---> 获得当前日期和时间 var now = new Date(); --->基于制定的日期和时间创建 var date = new Date(year,month,day,hour,minute,second); 需要注意的就是,Date.prototype中的方法都是基于UTC时间的,所以这些方法中month(0-11).day(1-31).星期几(
1.js没有块级作用域 if (true) { var color = “blue”; } alert(color); //”blue” for (var i=0; i < 10; i++){ doSomething(i); } alert(i); 2,变量定义 全局变量 变量定义:var和没有var function add(num1, num2) { var sum = num1 + num2; return sum; } alert(sum); //causes an error sinc