Situation
使用APPSmith完成前端页面搭建,Hasura+Graphql实现后端逻辑。 需要设置一个字段值为时间。后端数据库字段数据类型设置为标准时间格式
数据库存储值为
Task
对时间字段值处理一下,得到想要的效果
Action
前端获取后端数据时将其转换为我们常见的时间格式YY-MM-DD HH-MM-SS,我们使用moment库对获取到的数据进行转换
moment(currentRow.public_time).format("YYYY-MM-DD HH:mm:ss")
前端需要将修改后的时间以正确格式传回给后端时,同样需要处理一下
getNowFormatDate: () => {
let date = new Date();
let seperator1 = "-";
let seperator2 = ":";
let month = date.getMonth() + 1;
let strDate = date.getDate();
if (month >= 1 && month <= 9) {
month = "0" + month;
}
if (strDate >= 0 && strDate <= 9) {
strDate = "0" + strDate;
}
let currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate + " " + date.getHours() + seperator2 + date.getMinutes() + seperator2 + date.getSeconds();
return currentdate;
}
这样,前后端都能得到自己想要的时间数据格式了~
Result
- 遇到bug如何高效找到解决办法
- 避免相同的错误二次出现