本文经过了测试,解决getFullyear() is not a function等问题
效果如下:
首先:
Oracle中字段设置为DATE,MySQL中设置为DATETIME,MyBatis中会自动映射为TimeStamp;
其次:
model实体类中字段使用sql.Timestamp,如果设置为DATE类型,那么时分秒会显示为00:00:00这样显然没有什么意义。
1 function formatterdate(val, row) { 2 if (val != null) { 3 var date = new Date(val); 4 return date.getFullYear() + '-' + (date.getMonth() + 1) + '-' 5 + date.getDate(); 6 } 7 } 8 /** 9 * 格式化日期(不含时间) 10 */ 11 function formatterdate1(val, row) { 12 if (val != null) { 13 var date = new Date(val); 14 return date.getFullYear() 15 + "-"// "年" 16 + ((date.getMonth() + 1) > 10 ? (date.getMonth() + 1) : "0" 17 + (date.getMonth() + 1)) + "-"// "月" 18 + (date.getDate() < 10 ? "0" + date.getDate() : date.getDate()); 19 } 20 } 21 /** 22 * 格式化日期(含时间"00:00:00") 23 */ 24 function formatterdate2(val, row) { 25 if (val != null) { 26 var date = new Date(val); 27 return date.getFullYear() 28 + "-"// "年" 29 + ((date.getMonth() + 1) > 10 ? (date.getMonth() + 1) : "0" 30 + (date.getMonth() + 1)) + "-"// "月" 31 + (date.getDate() < 10 ? "0" + date.getDate() : date.getDate()) 32 + " " + "00:00:00"; 33 } 34 } 35 /** 36 * 格式化去日期(含时间) 37 */ 38 function formatterdate3(val, row) { 39 if (val != null) { 40 var date = new Date(val); 41 return date.getFullYear() 42 + "-"// "年" 43 + ((date.getMonth() + 1) > 10 ? (date.getMonth() + 1) : "0" 44 + (date.getMonth() + 1)) 45 + "-"// "月" 46 + (date.getDate() < 10 ? "0" + date.getDate() : date.getDate()) 47 + " " 48 + (date.getHours() < 10 ? "0" + date.getHours() : date 49 .getHours()) 50 + ":" 51 + (date.getMinutes() < 10 ? "0" + date.getMinutes() : date 52 .getMinutes()) 53 + ":" 54 + (date.getSeconds() < 10 ? "0" + date.getSeconds() : date 55 .getSeconds()); 56 } 57 }