19
05/2015
JS获得当前时间,并格式化
function getNowFormatDate() { var date = new Date(); var year = date.getFullYear(); var month = date.getMonth() + 1; var d = date.getDate(); var hour = date.getHours(); var minute = date.getMinutes(); var second = date.getSeconds(); if(month<10){ month = "0" + month; } if(d<10){ d = "0" + d; } if(hour<10){ hour = "0" + hour; } if(minute<10){ minute = "0" + hour; } if(second<10){ second = "0" + second; } return year + "-" + month + "-" + d + " " +hour + ":" + minute + ":" + second; }
注意这里的月要加1呀。
转载请注明:康瑞部落 » JS获得当前时间,并格式化
0 条评论