/** * 格式化日期为yyyy-MM-dd * @param data * @returns {*} */ function formatDate(data) { if (!data) { return ""; } var date = new Date(data); var year = date.getFullYear(); var month = (date.getMonth() + 1).toString().replace(/^(d)$/, "0$1"); var day = date.getDate().toString().replace(/^(d)$/, "0$1"); return year + "-" + month + "-" + day; }