day incorrect in angular material datepicker

后端 未结 15 1878
挽巷
挽巷 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

    OPTION 1: Had same issue and solved it in backed (Java) Can you solve this in your backend code.
    Presenting java code in case if anyone needs the same help. concept should be similar for other server side technologies too.

    Simulated the same bug and following are the analysis.

    PRINT Via JSON | "startdate": "2018-02-08T18:30:00.000Z" .

    PRINT BEFORE SUBMIT >>Fri Feb 09 2018 00:00:00 GMT+0530 (IST)

    public static String dateConversion(String dt) {
    
            Instant timestamp = Instant.parse(dt);
            ZonedDateTime isttime = timestamp.atZone(ZoneId.of("Asia/Kolkata"));
            System.out.println(isttime);
    
            System.out.println(DateTimeFormatter.ofPattern("dd-MM-yyyy").format(isttime));
            return DateTimeFormatter.ofPattern("dd-MM-yyyy").format(isttime);
        }
    

    OPTION 2: (solution in frontend) I have not tried this option but the documentation seems very clear.
    https://maggiepint.com/2016/05/14/moment-js-shows-the-wrong-date/ Check this out.

提交回复
热议问题