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>

 

posted @ 2017-03-27 15:59  shenxinpeter  阅读(972)  评论(0编辑  收藏  举报