【发布时间】:2019-04-21 00:24:01
【问题描述】:
我想显示使用以太坊在我的待办事项应用中创建任务的时间。
我得到task,其中包括content 和time,并在此代码中按状态设置任务。
constructor(props) {
super(props)
this.state = {
tasks: [],
}
}
・・・
for (var k = 1; k <= taskCount; k++) {
const task = await todoList.methods.tasks(k).call()
this.setState({
tasks: [...this.state.tasks, task]
})
}
然后,我使用map 来显示tasks 数组和time。
{ this.props.tasks.map((task, key) => {
return(
<div key={key}>
<p>{task.content}</p>
<p>{task.time}</p>
</div>
)
})}
结果,我得到了这样的数字
1555650125
1555651118
1555651169
1555664902
所以,我将{task.time} 更改为{Date(checkin.checkintime)},以便将该数字转换为正常时间。
但是,结果只显示数字。
Sat Apr 20 2019 09:20:57
Sat Apr 20 2019 09:20:57
Sat Apr 20 2019 09:20:57
Sat Apr 20 2019 09:20:57
我编写这段代码是为了检查Data() 是否正常工作,然后我可以得到正确的答案。
for (var k = 1; k <= taskCount; k++) {
const task = await todoList.methods.tasks(k).call()
const tasktime = new Date(task.checkintime * 1000)
console.log(tasktime)
this.setState({
tasks: [...this.state.tasks, task]
})
}
Fri Apr 19 2019 14:02:05
Fri Apr 19 2019 14:18:38
Fri Apr 19 2019 14:19:29
Fri Apr 19 2019 18:08:22
您能给我一些建议,让我在地图上显示时间吗?
【问题讨论】: