Javascript 如何在Material UI中的DatePicker中设置get格式和Date格式
我有一个日期选择器,只想获取YYYY-MM-DD格式的日期。 默认的日期时间格式为:Javascript 如何在Material UI中的DatePicker中设置get格式和Date格式,javascript,reactjs,material-ui,Javascript,Reactjs,Material Ui,我有一个日期选择器,只想获取YYYY-MM-DD格式的日期。 默认的日期时间格式为: Tue Feb 06 2018 00:00:00 GMT+0200 (FLE Standard Time) 如何格式化此日期选择器? 另外,如何将字段的颜色更改为另一种颜色,即写入日期的字段 handleChangeDate = (event, date) => { this.setState({ controllerDate: date }); }; onSubmitHandler(e){
Tue Feb 06 2018 00:00:00 GMT+0200 (FLE Standard Time)
如何格式化此日期选择器?
另外,如何将字段的颜色更改为另一种颜色,即写入日期的字段
handleChangeDate = (event, date) => {
this.setState({
controllerDate: date
});
};
onSubmitHandler(e){
e.preventDefault();
console.log(this.state.value)
console.log(this.state.controllerDate)
}
<div className="col-md-3">
<DatePicker hintText="Изберете дата" onChange={ this.handleChangeDate } />
</div>
handleChangeDate=(事件,日期)=>{
这是我的国家({
控制员日期:日期
});
};
onSubmitHandler(e){
e、 预防默认值();
console.log(this.state.value)
console.log(this.state.controllerDate)
}
以下是以YYYY-MM-DD格式获取日期的解决方案
class DatePickerExampleSimple扩展了React.Component{
建造师(道具){
超级(道具);
this.state={}
this.handleChangeDate=this.handleChangeDate.bind(this);
this.formatDate=this.formatDate.bind(this);
}
格式日期(日期){
设d=新日期(日期),
月份=“”+(d.getMonth()+1),
日期=“”+d.getDate(),
year=d.getFullYear();
如果(月长<2)月='0'+月;
如果(日长<2)天='0'+天;
返回[年、月、日]。加入('-');
}
handleChangeDate=(事件,日期)=>{
设formattedDate=this.FormattDate(日期);
console.log(格式化日期);
这是我的国家({
controllerDate:formattedDate
});
};
render(){
返回(
新选择的值是{this.state.controllerDate}
)
}
};
导出默认日期选择器示例简单代码>
以下是以YYYY-MM-DD格式获取日期的解决方案
class DatePickerExampleSimple扩展了React.Component{
建造师(道具){
超级(道具);
this.state={}
this.handleChangeDate=this.handleChangeDate.bind(this);
this.formatDate=this.formatDate.bind(this);
}
格式日期(日期){
设d=新日期(日期),
月份=“”+(d.getMonth()+1),
日期=“”+d.getDate(),
year=d.getFullYear();
如果(月长<2)月='0'+月;
如果(日长<2)天='0'+天;
返回[年、月、日]。加入('-');
}
handleChangeDate=(事件,日期)=>{
设formattedDate=this.FormattDate(日期);
console.log(格式化日期);
这是我的国家({
controllerDate:formattedDate
});
};
render(){
返回(
新选择的值是{this.state.controllerDate}
)
}
};
导出默认日期选择器示例简单代码>
利用这一时刻获得你想要的格式。。。使用你可以得到任何你想要的格式
handleChangeDate = (event, date) => {
this.setState({
controllerDate: moment(date).format('YYYY-MM-DD')
});
};
onSubmitHandler(e){
e.preventDefault();
console.log(this.state.value)
console.log(this.state.controllerDate)
}
<div className="col-md-3">
<DatePicker hintText="Изберете дата" onChange={ this.handleChangeDate } />
</div>
handleChangeDate=(事件,日期)=>{
这是我的国家({
controllerDate:时刻(日期).格式('YYYY-MM-DD')
});
};
onSubmitHandler(e){
e、 预防默认值();
console.log(this.state.value)
console.log(this.state.controllerDate)
}
利用这一时刻获得你想要的格式。。。使用你可以得到任何你想要的格式
handleChangeDate = (event, date) => {
this.setState({
controllerDate: moment(date).format('YYYY-MM-DD')
});
};
onSubmitHandler(e){
e.preventDefault();
console.log(this.state.value)
console.log(this.state.controllerDate)
}
<div className="col-md-3">
<DatePicker hintText="Изберете дата" onChange={ this.handleChangeDate } />
</div>
handleChangeDate=(事件,日期)=>{
这是我的国家({
controllerDate:时刻(日期).格式('YYYY-MM-DD')
});
};
onSubmitHandler(e){
e、 预防默认值();
console.log(this.state.value)
console.log(this.state.controllerDate)
}
这不是引导问题。这不是引导问题。