//转换列值 //数据库表字段是datetime(2,7) transformColumnValue(scope, column) { const type = column.type; let value = scope.row[column.property.dataField.value]; console.log('value', value, Date.parse(value), new Date(Date.parse(value))); //value = '2019-12-11 16:15:00'; value = 'Wed Dec 11 2019 16:15:00 GMT+0800 (中国标准时间)'; if (this.checkDateIsIllegal(value)) { const dateValue = new Date(Date.parse(value)); return this.tansfromValue(dateValue, type); } return value; }, //日期类型是否转换成功 checkDateIsIllegal(value) { const dateParseValue = Date.parse(value); if (dateParseValue < 0) return false; if (isNaN(dateParseValue)) return false; return true; }, //转换值 tansfromValue(dateValue, type) { switch (type) { case 'date': dateValue = this.transformDateValue(dateValue); break; case 'time': dateValue = this.transformTimeValue(dateValue); break; case 'datetime': dateValue = this.transformDateTimeValue(dateValue); break; default: break; } return dateValue; }, //转换日期值 transformDateValue(dateValue) { const strMonth = (dateValue.getMonth() + 1).toString().padStart(2, '0'); const strDate = dateValue.getDate().toString().padStart(2, '0'); //时间格式yyyy-MM-dd return `${dateValue.getFullYear()}-${strMonth}-${strDate}`; }, //转换时间值 transformTimeValue(dateValue) { const strHours = dateValue.getHours().toString().padStart(2, '0'); const strMinutes = dateValue.getMinutes().toString().padStart(2, '0'); const strSeconds = dateValue.getSeconds().toString().padStart(2, '0'); return `${strHours}:${strMinutes}:${strSeconds}`; }, //转换日期时间值 transformDateTimeValue(dateValue) { return `${this.transformDateValue(dateValue)} ${this.transformTimeValue(dateValue)}`; },
标签:return,前端,value,js,日期,toString,dateValue,Date,const From: https://www.cnblogs.com/jishugaochao/p/12485110.html