Search code examples
angulardatetimedate-rangeng-zorro-antd

NG-ZORRO range-picker set hour for start date at 00:00:00 and for end date at 23:59:59


Having this example, how can I set the hours of the start date and end date to 00:00:00 and 23:59:59 respectively?

I don't really want to set this manually like this:

export class MyComponent {
  dateRange = [];

  onChange(result): void {
    this.dateRange[0].setHours(0,0,0);
    this.dateRange[1].setHours(23,59,59);
  }
}

Solution

  • If it is purely visual you could use pipes instead (https://angular.io/guide/pipes).

    EDIT: one function for multiple editors

    You can use one onChange(result) call with every nzOnCalendarChange date range you have. Then instead of changing the this.dateRange change result as it should be the date[] of the widget. Changing result will also result in the binding object to change as long as it is a 2 way bind [()]