Date()常用方法
var date = new Date() console.log(date); //Fri Oct 29 2021 14:18:13 GMT+0800 (中国标准时间) console.log(date.getMonth()); //获取月份(0-11,0代表1月,所以在显示当前时间的时候需要date.getMonth() + 1) console.log(date.getYear()); console.log(date.getFullYear()); //2021 console.log(date.getDate()); // 获取日(1-31) console.log(date.getDay()); //获取星期?(0-6,0代表星期天) console.log(date.getTime()); //1635487678770 获取时间(从1970.1.1开始的毫秒数) console.log(date.getHours()); //获取小时数(0-23) console.log(date.getMinutes()); //获取分钟数(0-59) console.log(date.getSeconds()); //获取秒数(0-59) console.log(date.getMilliseconds()); // //获取毫秒数(0-999) console.log(date.toLocaleString()); //2021/10/29 下午2:10:06获取日期与时间 console.log(date.toLocaleDateString()); //2021/10/29 console.log(date.toLocaleTimeString()); //下午2:11:0
执行结果
标签:常用,console,log,获取,Vuejs,date,2021,Date From: https://www.cnblogs.com/phoenixy/p/17701359.html