How to change ngbDatepicker date format from JSON to YYYY/MM/DD

前端 未结 3 1358
南笙
南笙 2020-12-21 02:29

I\'m working with ngbDatepicker this is giving me JSON date format like:

{ year: 2019, month: 6, day: 9 }

How can I convert this into YYYY/

3条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-21 03:12

    if you are using date field you need to bind the model in ts. in the html, call the method dateselect like this

     (dateSelect)="onDateSelect($event)"
    

    Full code:

     
              

    In the type script, use the following code.This is applicable only if you are using Ngbdate picker.

     onDateSelect(event) {
      let year = event.year;
      let month = event.month <= 9 ? '0' + event.month : event.month;;
      let day = event.day <= 9 ? '0' + event.day : event.day;;
      let finalDate = year + "-" + month + "-" + day;
     }
    

提交回复
热议问题