JavaScript中Date对象的方法解析
上篇文章讲到了JavaScript的Date对象,对Date对象的创建和属性进行了讲解,这篇博客我们来讲一讲Date对象的方法有哪些。
1.获取日期的方法
// 获取当前的日期
var oDate=new Date();
// 方法 描述
// getDate() 从 Date 对象返回一个月中的某一天 (1 ~ 31)。
console.log(oDate.getDate());
// getDay() 从 Date 对象返回一周中的某一天 (0 ~ 6)。
console.log(oDate.getDay());// 0代表周日
// getFullYear() 从 Date 对象以四位数字返回年份。
console.log(oDate.getFullYear());
// getMonth() 从 Date 对象返回月份 (0 ~ 11)。
console.log(oDate.getMonth());// 一月份 是 0
// getHours() 返回 Date 对象的小时 (0 ~ 23)。
console.log(oDate.getHours());