JS格式化日期方法
在前端开发有时候需要在前台处理日期格式,但是JS又没有提供DateFormat方法,因此自定义了如下函数供日期转换。
function getNowFormatDate(date) { var seperator1 = "-"; var seperator2 = ":"; var year = date.getFullYear(); var month = numberFormat(date.getMonth() + 1); var strDate = numberFormat(date.getDate()); var hours = numberFormat(date.getHours()); var minutes = numberFormat(date.getMinutes()); var seconds = numberFormat(date.getSeconds()); var currentdate = year + seperator1 + month + seperator1 + strDate + " " + hours + seperator2 + minutes + seperator2 + seconds; return currentdate; } function numberFormat(number){ return number > -1 && number < 10?"0"+number:number; }