【发布时间】:2018-11-09 20:19:42
【问题描述】:
我有一个表单,我想设置一个输入文本字段来显示当前日期和时间:
我有以下功能:
const getDateTime = () => {
let tempDate = new Date();
let date = tempDate.getFullYear() + '-' + (tempDate.getMonth()+1) + '-' + tempDate.getDate() +' '+ tempDate.getHours()+':'+ tempDate.getMinutes()+':'+ tempDate.getSeconds();
const currDate = "Current Date= "+date;
return (
{currDate}
);
}
对于输入文本字段: 在构造函数中,我设置了状态:
reportStartDate: '',
超文本设置如下:
<div className="form-group">
<label htmlFor="reportStartDate">Report Start Date:</label>
<input type="text" name="reportStartDate" className="form-control" placeholder="Report Start Date" value={this.state.reportStartDate} onChange={e => this.change(e)} />
</div>
如何获取当前日期和时间以显示在文本字段中?
【问题讨论】:
-
在哪里调用 getDateTime() 函数?
标签: javascript reactjs