day incorrect in angular material datepicker

后端 未结 15 1881
挽巷
挽巷 2020-12-08 11:01

When I select a date I see the correct date in the field but, when I save, the datepicker send the day before the date I have selected ( 3 hours offset ) i am using angular

15条回答
  •  猫巷女王i
    2020-12-08 11:30

    Maybe it will be helpful for someone. It is my example method in which i erase TimeZone OffSet from component date

      addPriceListPeriod(priceListId: number, periodDateFrom: Date) {
    
        let UTCDate = Date.UTC(periodDateFrom.getFullYear(), periodDateFrom.getMonth(), periodDateFrom.getDate()) - periodDateFrom.getTimezoneOffset();
    
        periodDateFrom = new Date(UTCDate);
    
        const tempObject = {
          priceListId,
          fromDate: periodDateFrom
        }
        return this.httpClient.post('PriceLists/addPriceListPeriod', tempObject);
      }
    

提交回复
热议问题