JS如何获得此时此刻的时间
<script type="text/javascript">
//
var now = new Date(); // new新创建
//console.log(now); // now包含日期 时间等信息
// 将日期格式转成字符串
function dataToString(d){
var weekArr=["星期日","星期一","星期二","星期三","星期四","星期五","星期六"];
var year=d.getFullYear();
// alert(year);
var month=d.getMonth()+1;
// alert(month);
var date=d.getDate();
// alert(date);
var h=d.getHours();
// alert(h);
var m=d.getMinutes();
// alert(m);
var s=d.getSeconds();
// alert(s);
var str=year+"年"+month+"月"+date+"日"+" ";
str+=h+":"+m+":"+s+" ";
str+=" "+weekArr[d.getDay()];
return str;
}
alert(dataToString(now));
</script>