I m using NGX-Bootstrap for my angular6 project. I have reactive form and added datepicker to it and while returning the value from datepicker getting full format ex: "2018-11-07T05:12:35.000Z". But I want in MM-DD-YYYY.
Go to line 1399 and find format: 'mm/dd/yyyy' . Now you can change the date format here.
bsconfig. json is the single, mandatory build meta file needed for rescript . The complete configuration schema is here. We'll non-exhaustively highlight the important parts in prose below.
Angular Bootstrap 5 Datepicker. Date picker is a plugin that adds the function of selecting time without the necessity of using custom JavaScript code.
Before returning the date, convert the date format as the following:
let date = new Date(dateValue).toLocaleDateString();
then assign date
to the form controller
to be more generic you can create a directive which returns the date in the format you want. for eg.
<input changeDateFormat type="text" placeholder="Datepicker" class="form-control" #dp="bsDatepicker" bsDatepicker [(bsValue)]="bsValue">
export class changeDateFormatDirective implements OnChanges {
@Input() bsValue: Date;
@Output() bsValueChange = new EventEmitter();
constructor(private cdr: ChangeDetectorRef) { }
ngOnChanges(changes: SimpleChanges) {
//change Date format here, you can import format date from @angular/common
this.bsValueChange.emit(newDateFormat);
this.cdr.detectChanges();
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With