javascript函数之获取当前日期
<script>
function CurentTime() { var now = new Date(); var year = now.getFullYear(); //年 var month = now.getMonth() + 1; //月 var day = now.getDate(); //日 var hh = now.getHours(); //时 var mm = now.getMinutes(); //分 var ss = now.getSeconds(); //秒 if (month < 10) { month = '0' + month; } if (day < 10) { day = '0' + day; } if (hh < 10) { hh = '0' + hh; } if (mm < 10) { mm = '0' + mm; } if (ss < 10) { ss = '0' + ss; } //时分秒 var result = hh + ":" + mm + ":" + ss; //年月日时分秒 // var result = year + '-' + month + '-' + day + ' ' + hh + ":" + mm + ":" + ss; return result; } </script>