因为项目里经常设计JS 中的Date对象,故来整理一下常用的构建和方法。
实例化
- new Date(); 返回当前日期
- new Date(value); value是一个代表时间的字符串,例如“December 17, 1995 03:24:00”
- new Date(dateString); dateString: 一个ISO字符串“1995-12-17T03:24:00”
- new Date(year, monthIndex [, day [, hours [, minutes [, seconds [, milliseconds]]]]]); 比较少见,monthIndex从0开始,故0代表一月,例如:new Date(1970,0,1) ⇒ 1970年1月1日
Prototype.method()
- Date.prototype.getDate() //local时间一个月的第几天
- Date.prototype.getDay() //local时间一个星期的第几天
- Date.prototype.getFullYear(); //返回年份
- Date.prototype.toISOString(); // ISO格式时间 “2004-05-03T17:30:08”
- Date.prototype.toLocaleString() // 转化未本地日期
- Date.prototype.toUTCString() // 转化为UTC时间,英国时区时间