{<Form.Item label="Due Date" name="duedate" >
<Input prefix={<ClockCircleOutlined />} placeholder="YYYY-MM-DD HH:mm:ss"/>
{/* <DatePicker
showTime
format="YYYY-MM-DD HH:mm:ss"
style={{ width: "100%" }}
/> */}
本来想用datepicker,不过我实在是驾驭不了它,传输的那些函数根本处理不了,也没有找到合适的转化函数。。(后面发现在前后端连起来之后就可以直接用了)
输入字符串之后
form.duedate=new Date(form.duedate).getTime();
const{success,data}=await addBwicApi(form);
TS里适合转时间戳的函数只找到gettime。。
后端返回时间戳数据后遍历转为字符串:
function formatDate(time:any):string{
let date = new Date(time);
let YY = date.getFullYear();
let MM = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
let DD = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
let hh = date.getHours() < 10 ? "0" + date.getHours() : date.getHours();
let mm = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();
let ss = date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
// 这里修改返回时间的格式
return YY + "-" + MM + "-" + DD + " " + hh + ":" + mm + ":" + ss;
}
const [ddd,setddd]=useState<BwicItems[]>();
const onClick = async () => {
const { success, data } = await getBwicApi();
// console.log(1111);
// console.log(data);
for (let datai of data) {
//datai.duedate=new Date(datai.duedate);
datai.duedate=formatDate(datai.duedate);
}
setddd(data);
}//bwic?.AddedBwic
return(
<div>
<Button onClick={onClick}>刷新!</Button>
<div>23333</div>
<Table columns={columns} dataSource={ddd} onChange={onChange} key="cuisp" />
<Button title="刷新" onClick={onClick}/>
</div>);
duedate终于正常了,虽然还是抛弃了datepicker但勉强能用,先转化了一次时间戳传进去,显示的时候又遍历了一遍data.duedate变回字符串,让它在数据库和前端都能完美展示了。