我想在table.when的列中代替datepicker发布日期 我在列表中发布了datepicker,它应该被转换 到天。例如,当我发布今天的日期,它应该显示1天 在列表中,2天为tommorow等。 the screenshot of my project is here。如何解决这个问题所以请帮帮我。
我的项目代码看起来像这样。只发布日期不是几天。
const datetime = new Date(2016, 8, 20);
export default class SupportInterface extends Component {
constructor(props) {
super (props);
this.state = {
active: false,
socket: null,
timestampBalance:datetime,
supportInfo: [],
modalComapnyName:'',
modalVehicleNo:'',
modalSimNo:'',
modalLat: '27.931963',
modalLng: '84.85758'
}
此代码从表单发布日期。
saveForm(){
axios({
method:'post',
url: 'https://something.something.com.np/updateRechargeStatus',
data:{
timestamp:moment(this.state.timestampBalance).format("MMM DD, YYYY"),
balance: '51',
sim_number:this.state.modalSimNo
}
})
.then((response)=>{
if(response.data.success){
this.setState({
active:false
});
this.getSupportInfo();
}else{
alert("unable to update balance");
}
})
.catch((error)=>{
throw('error',error);
});
}
我正在使用bootstrap表来显示这样的日期
<TableHeaderColumn dataField="timestamp_for_balance" dataSort={true}>Recharge date</TableHeaderColumn>
datepicker表单是这样的。
<DatePicker label='Date' onChange={(text) => this.setState({timestampBalance: text})} value={this.state.timestampBalance} />
答案 0 :(得分:1)
在此处提出一个旧问题:您可以使用difference function in moment
var a = moment(this.state.timestampBalance);
var b = moment();
a.diff(b, 'days') //number of days between today and timestampBalanceDate
因为如果你今天希望成为1,只需在差异中添加1。