Prettify values using ng2 ion range slider - angular

736 Views Asked by At

I am trying to implement date selection slider using ng2 ion range slider in angular https://github.com/PhilippStein/ng2-ion-range-slider

  ngOnInit() { 
    this.myMaxDateVal = Date.now();
    var formattedDate = new Date(this.myMaxDateVal);
    this.myMinDateVal = formattedDate.setFullYear(formattedDate.getFullYear()-1);
  }
   <ion-range-slider #defaultSlider
      type = "double"
      [min] = "myMinDateVal"
      [max] = "myMaxDateVal"
      [hide_min_max] = "true"
      [from] = "fromdate"
      [to] = "todate"
      [hide_from_to] = "false"
      grid = "false"
      grid_num = "22"
      (onUpdate) = "myOnUpdate($event)"
      (onChange) = "myOnChange($event)"
      (onFinish) = "myOnFinish($event)">
      </ion-range-slider>

screenshot enter image description here

The hovers on the date selection slider are displaying in milliseconds, I would like to prettify them to "MM/DD/YYYY" format. Can anyone please tell me how to prettify the format of the hovers from milliseconds to "MM/DD/YYYY".

1

There are 1 best solutions below

0
On

Try this:

this.myMaxDateVal = new Date(Date.now()).toLocaleString()

It should output the string: "5/14/2018, 3:14:10 PM"

Then just split it by a comma.