var date = new Date();
console.log(date.getDate() ) 获取日 1-31
console.log(date.getDay () ) 获取星期 0-6(0代表周日)
console.log(date.getMonth () ) 获取月 0-11(1月从0开始)
console.log(date.getFullYear () ) 获取完整年份(浏览器都支持)
console.log(date.getHours () ) 获取小时 0-23
console.log(date.getMinutes () ) 获取分钟 0-59
console.log(date.getSeconds () ) 获取秒 0-59
console.log(date.getMilliseconds () ) 获取毫秒 (1s = 1000ms)
console.log(date.getTime () ) 返回累计毫秒数(从1970/1/1午夜)
var date1 = Date.now();
var date2 = +new Date();
var date3 = new Date().getTime();
var date4 = new Date().valueOf();
console.log(date1);
console.log(date2);
console.log(date3);
console.log(date4);
date对象常用方法
最新推荐文章于 2024-08-04 10:58:32 发布