momentjs - Reactjs - Moment -
am not able parse date mongodb , render in textbox.
mongodb date format : mmm dd yyyy hh mm ss a
<input name="date" type="date" disabled={ this.state.mode } value={ this.state.item.date ? <moment format="dd-mmm-yyyy">{ this.state.item.date }</moment> : null } classname="form-control" onchange={ this.handleinputchange } />
am trying above code. please suggest..
you can make use of moment.js library. install package dependency like
npm install -s moment
then use in input like
<input name="date" type="date" disabled={ this.state.mode } value={ this.state.item.date ? moment(new date(this.state.item.date)).format("dd-mmm-yyyy"): ''} classname="form-control" onchange={ this.handleinputchange } />
demo:
var data = 'thu dec 29 2011 20:14:56 gmt-0600 (cst)'; console.log(moment(new date(data)).format("dd-mmm-yyyy"))
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.18.1/moment.min.js"></script>
Comments
Post a Comment