//function ad(){
// var timer = new Date();
// var sum= timer.getTime(); //获取当前的毫秒
// var yd = new Date(2020,1,1);
// var sun= yd.getTime(); //获取元旦的毫秒
// var nc = sun-sum; 获取时间戳
// var seconds = parseInt(nc/1000)%60;
// var minutes = parseInt(nc/1000/60)%60;
// var hours = parseInt(nc/1000/60/60)%24;
// var date = parseInt(nc/1000/60/60/24)%365;
// var years = parseInt(nc/1000/60/60/24/365);
// var str='距离元旦还有:'+years+'年'+date+'日'+hours+'时'+minutes+'分'+seconds+'秒';
//// document.write(str);
// return str
//}
获取date时间的单位
var date=new Date();
console.log(date);
var nian= date.getFullYear();
var yue=date.getMonth()+1;
var ri = date.getDate();
var shi=date.getHours();
var fen=date.getMinutes();
console.log(nian+"年"+yue+"月"+ri+"日"+shi+"时"+fen+"分");
console.log(date.toLocaleDateString());
console.log(date.toLocaleString());
网友评论