day incorrect in angular material datepicker

后端 未结 15 1892
挽巷
挽巷 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条回答
  •  北荒
    北荒 (楼主)
    2020-12-08 11:19

    You can modify your date format before sending to the server:

    public saveYourDate(date: Date): Observable {
            const formattedDate = date.toLocaleDateString();
            return this.http.post(`${this.yourPathVariable}/date`, formattedDate);
        }
    

    In this case you don't specify the time so the date is being sent as a string in the format depending on locale conventions like this: '10/30/2020'.

提交回复
热议问题