javascript的date对象操作笔记
2016-12-02 00:39
323 查看
一、setDate()和getDay()
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>副本</title> </head> <body> <script type="text/javascript"> console.log("/////////////") var now1 = new Date(); console.log(now1) console.log(typeof(now1)) console.log("/////////////") var now2 = new Date(); var now3 = now2.setDate(1);//对now2操作后返回值为number console.log(now3) console.log(typeof(now3)) console.log(now2.getDay()) console.log("////////////") var now4 = new Date() now4.setDate(1) //对now4直接操作,得到now4还是object console.log(now4) console.log(typeof(now4)) </script> </body> </html>
得到的结果是:
所以:
var now = new Date(); var firstDay = now.setDate(1).getDay();
会提示错误:Uncaught TypeError: now.setDate(…).getDay is not a function
正确写法是:
var now = new Date(); now.setDate(1); var firstDay = now.getDay();
相关文章推荐
- javascript笔记:Date对象及操作方法
- JavaScript 学习笔记— —Date对象
- javascript学习笔记--js对html对象的原生操作
- JavaScript 之Date 对象操作
- 简单封装JavaScript Date对象操作
- JavaScript 对象属性操作和方法学习笔记(上)
- javascript学习笔记--数组对象的操作
- ArcGIS API for JavaScript 4.2学习笔记[20] 使用缓冲区结合Query对象进行地震点查询【重温异步操作思想】
- javascript对文档对象模型DOM的基本操作学习笔记
- javascript操作Date对象
- javascript 红宝书笔记之如何使用对象 如何操作数组
- Javascript 笔记与总结(2-3)Javascript 运算符、控制结构与对象操作
- javascript基础笔记(十二)之js的Date对象
- JavaScript笔记(二) ——Array和Date对象方法(转)
- JavaScript中Date(日期对象),Math对象--学习笔记
- 详解JavaScript对Date对象的操作问题(生成一个倒数7天的数组)
- 详解JavaScript对Date对象的操作问题(生成一个倒数7天的数组)
- 【Web前端学习笔记】Javascript_03_常用对象:String,Number,Math,Date,网页时针
- JavaScript Date 对象笔记
- JavaScript Date日期对象的常用操作