日期对象
- 一个案例解决
function formartDate(date) {
var arr = [];
arr.push(date.getFullYear());//获取年份
arr.push("-");
arr.push(date.getMonth() + 1);//获取月份
arr.push("-");
arr.push(date.getDate());//获取日期
arr.push(" ");
arr.push(date.getHours());//获取小时
arr.push(":");
arr.push(date.getMinutes());//获取分钟
arr.push(":");
arr.push(date.getSeconds());//获取秒
return arr.join("");
}
- 注意点: 月份为0~11月,所以获取的月份需要+1才是实际月份
Math
常用对象
Math.PI; 圆周率
Math.floor() 向下取整
Math.ceil() 向上取整
Math.round() 四舍五入
Math.abs() 绝对器
Math.random() 生成随机数