javascript獲取當(dāng)前時(shí)間,沒什么好說的,直接上代碼。
首選獲取當(dāng)前時(shí)間
var d=new Date() 獲取系統(tǒng)當(dāng)前時(shí)間
1.獲取年份
var d=new Date();
console.log(d.getFullYear());//2022
var born=new Date("1999");
console.log(born.getFullYear())//1999
2.獲取當(dāng)前月份
var d=new Date();//從0開始到11
console.log(d.getMonth());//2022-11-11:6
console.log(d.getMonth()+1);//11
3.獲取當(dāng)前天數(shù)
var d=new Date();
console.log(d.getDate());//1-31
var d=new Date("July 21,1983");
console.log(d.getDate())//21
4.獲取當(dāng)前周數(shù)
var d=new Date()
console.log(d.getDay());
5.獲取當(dāng)前時(shí)間
getHours():0-23
getMinutes():0-59
getSecond():0-59
var d = new Date();
var hour= d.getHours();*//得到小時(shí)數(shù)*
var minute= d.getMinutes();*//得到分鐘數(shù)*
var second= d.getSeconds();*//得到秒數(shù) |