This article brings you an introduction and examples of Date methods in JavaScript. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.
Date method
console.log(typeof Date);// "function"
Date instance
console.log(typeof new Date()); // "object" console.log(new Date()); // 获取本机的系统时间; var time = new Date(); console.log(time.getFullYear()); // 获取时间年; console.log(time.getMonth()) // 获取时间月 取值范围【0-11】 console.log(time.getDate()); // 获取时间日【1-31】 console.log(time.getDay()); // 获取星期几;【0-6】 星期日是0; console.log(time.getHours()) // 获取小时数 【0-23】 console.log(time.getMinutes()); // 获取分钟数 【0-59】 console.log(time.getSeconds()); // 获取时间秒【0-59】 console.log(time.getMilliseconds()); // 获取毫秒数【0-999】 console.log(time.getTime()); // 当前时间距离1970-1-1日早上八点的毫秒数; console.log(Date.now()); // 时间戳:
Related recommendations:
Code implementation of javascript event delegation and code optimization
JS tutorial--Knapsack capacity problem of dynamic programming algorithm
The above is the detailed content of Introduction and examples of Date methods in JavaScript. For more information, please follow other related articles on the PHP Chinese website!