用于CV
// Date类型
(function () {
// 1. 获取时间对象
//(1)当前时间对象
var now = new Date();
console.log("now", now);//Tue Jan 07 2020 20:43:02 GMT+0800 (中国标准时间)
//(2)获取某天的时间对象,首先获取时间戳,然后使用Date生成对象
var millsecond = Date.UTC(1980, 1, 3);//获取时间戳
var thatNow = new Date(millsecond);//使用Date生成对象
console.log("thatNow", thatNow);
// 3. 获取相应的时间戳
/**
* (1) Date.parse()
* 接收一个表示日期的字符串参数(周几 月名 日 年 时:分:秒 时区)
* 例1:年/月/日
* 例2:英文月名 日,年
* 例3:Sun Feb 03 1980 08:00:00 GMT+0800
* */
var someDate = Date.parse("May 25,2008");
console.log("someDate", someDate);//时间戳
/**
* (2) Date.UTC(年,月,日,时,分,秒)
* 注意:1. 月份是以0开始,0代表1月份
* 2. 日数的选择范围是1~31
* 3. 时0~23(0代表24时)
* 4. 分、秒0~59(0代表60秒)
*/
var y2k = Date.UTC(2000, 0);
console.log("y2k", y2k);//时间戳
//4. 获取时间戳
var start = Date.now();//获取时间戳
var stop = +new Date();//获取时间戳(去掉+,不显示时间戳)
console.log(start);
console.log(stop);
//5. 获取年月日时分秒
var nowDate = new Date();
var year = nowDate.getFullYear();//获取年
var month = nowDate.getMonth();//获取月 0~11
var day = nowDate.getDate();//获取日 1~(28,31)
var week = nowDate.getDay();//获取星期 0~6
var hour = nowDate.getHours();//获取时 0~23
var minutes = nowDate.getMinutes(); //获取分 0~59
var second = nowDate.getSeconds(); // 获取秒 0~59
var weekName = ["一","二","三","四","五","六","日"];
console.log(`${year}年-${month+1}月-${day}日,星期${weekName[week]} ${hour}时:${minutes}分:${second}秒`);
//6.
var theDate = new Date();
console.log(theDate.toDateString());//Thu Feb 17 2022
console.log(theDate.toTimeString());//23:26:43 GMT+0800 (中国标准时间)
console.log(theDate.toLocaleDateString());//2022/2/17
console.log(theDate.toLocaleTimeString());//下午11:26:43
console.log(theDate.toUTCString());//Thu, 17 Feb 2022 15:26:43 GMT
})();