【JS学习笔记】时间与日期

晓石头的博客
邮箱:[email protected]

转载请注明出处,原文链接:http://blog.csdn.net/qiulanzhu/article/details/50663541


var data = new Date();		
document.write(data +"
"); //显示结果因浏览器而异 //两个静态方法 //Date.parse(); document.write(Date.parse("1/31/2016") +"
");//返回毫秒数 var data2 = new Date(Date.parse("1/31/2016")); document.write(data2 +"
"); var data3 = new Date("1/31/2016"); //Date.parse()会被后台调用 document.write(data3 +"
"); //Date.UTC(); var data4 = new Date(Date.UTC(2016, 3, 3, 17, 4, 6)); //月加1,时加8 document.write(data4 +"
"); var data5 = new Date(2016, 3, 3, 17, 4, 6); //只有月加1 document.write(data5 +"
"); //通用方法 var cup = new Date(2016,1,31,16,42,16); document.write(cup +"
"); //Wed Mar 02 2016 16:42:16 GMT+0800 document.write(cup.toString() +"
"); //Wed Mar 02 2016 16:42:16 GMT+0800 document.write(cup.toLocaleString() +"
"); //2016/3/2 下午4:42:16(ps:谷歌返回和上面一样) document.write(cup.valueOf() +"
"); //1456908136000 //格式化 var suger = new Date(2016,0,31,16,42,16); document.write(suger.toDateString() +"
"); document.write(suger.toTimeString() +"
"); document.write(suger.toLocaleDateString() +"
"); document.write(suger.toLocaleTimeString() +"
"); document.write(suger.toUTCString() +"
"); //组件方法 var face = new Date(2016,0,31,16,42,16); document.write(face.getTime() +"
"); //获取日期的毫秒数 //face.setTime(1456908136000) //设置日期毫秒数 document.write(face.getFullYear() +"
"); //获取年 document.write(face.getMonth() +"
"); //获取月,从0开始算 document.write(face.getDate() +"
"); //获取日 document.write(face.getDay() +"
"); //获取星期,0表示星期日,6表示星期六 document.write(face.getHours() +"
"); //获取时 document.write(face.getMinutes() +"
"); //获取分 document.write(face.getSeconds() +"
"); //获取秒 document.write(face.getMilliseconds() +"
"); //获取毫秒 document.write(face.getTimezoneOffset() +"
"); //获取本地时间和UTC时间相差的分钟数


你可能感兴趣的:(【JS学习笔记】时间与日期)